0
我想在Ember.js應用程序中使用X可編輯選擇2。X可編輯選擇2和Ember.js
我創建了以下編輯元素:
<a href="javascript:;" class="input-xlarge editable" data-url="children" multiple="multiple" data-pk="1">Test parent</a>
而且使用這個JavaScript:
$(function() {
$.fn.editable.defaults.mode = 'inline';
$('.editable').editable({
type: 'select2',
select2: {
placeholder: "Search for a parent...",
minimumInputLength: 3,
multiple: true,
ajax: {
url: 'http://localhost:8001/api/parents',
dataType: 'json',
data: function (term, page) {
return { q: term }; // search term
},
results: function (data, page) {
return {results: data};
}
},
formatResult: function(result) {
return result.first_name + ' ' + result.last_name;
},
formatSelection: function(selection) {
return selection.first_name + ' ' + selection.last_name;
}
},
// Used for sending JSON instead of form data
params: function(params) {
return JSON.stringify(params);
}
});
});
當我點擊Test child
出現的AJAX微調,並在控制檯下面的錯誤顯示:Uncaught TypeError: Cannot read property 'id' of null
它是指:
$.fn.select2.defaults = {
...
id: function (e) { return e.id; },
...
}
我在這裏做錯了什麼?謝謝!
難道你正在處理一個jQuery的問題?我只是看着x-editable,注意到它不支持jQuery 1.9.x,而這是EmberJS支持的唯一jQuery版本。無論如何,它只是一個飛行員。祝你好運回答。 – ken
你從哪裏讀到x-editable不支持jQuery 1.9?我找不到它。 – EsTeGe
這是在他們的GitHub問題頁面上。他們也至少討論了部分解決方法,但我暗中希望Ember在2.x正式發佈時支持2.x(不是那種等待永遠是好的解決方案)。讓我看看我能否找到網址。 – ken