質問編集履歴

2

タイトル修正

2016/04/03 14:53

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Rails タグ入力時に、使用数を表示させたい。
1
+ Rails タグオートコンプリート時に、使用数を表示させたい。
test CHANGED
File without changes

1

Coffeescript to Javascript

2016/04/03 14:53

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -62,31 +62,49 @@
62
62
 
63
63
 
64
64
 
65
- ```coffeescript
65
+ ```javascript
66
66
 
67
- items.coffee
67
+ items.js
68
68
 
69
69
 
70
70
 
71
- # タグのオートコンプリートと編集画面時のタグセット処理
71
+ // タグのオートコンプリートと編集画面時のタグセット処理
72
72
 
73
- $(document).on 'ready page:load', ->
73
+ $(document).on('ready page:load', function() {
74
74
 
75
- $('#item-tags').tagit
75
+ var i, len, ref, results, tag;
76
76
 
77
- placeholderText: 'タグを入力してください・・・'
77
+ $('#item-tags').tagit({
78
78
 
79
- fieldName: 'item[tag_list]'
79
+ placeholderText: 'タグを入力してください・・・',
80
80
 
81
+ fieldName: 'item[tag_list]',
82
+
81
- singleField: true
83
+ singleField: true,
82
84
 
83
85
  availableTags: gon.available_tags
84
86
 
85
- if gon.item_tags?
87
+ });
86
88
 
87
- for tag in gon.item_tags
89
+ if (gon.item_tags != null) {
88
90
 
91
+ ref = gon.item_tags;
92
+
93
+ results = [];
94
+
95
+ for (i = 0, len = ref.length; i < len; i++) {
96
+
97
+ tag = ref[i];
98
+
89
- $('#item-tags').tagit 'createTag', tag
99
+ results.push($('#item-tags').tagit('createTag', tag));
100
+
101
+ }
102
+
103
+ return results;
104
+
105
+ }
106
+
107
+ });
90
108
 
91
109
  ```
92
110