我試圖創建一個可排序的項目列表。在這一刻,我正在使用jQuery對此進行排序。該列表使用Ember視圖創建。當一件物品被丟棄時,我想用新訂單更新Ember模型。在稍後階段,我想將其保存回服務器。在jQuery事件處理函數中使用Ember.js模型
在下面的代碼中,您可以看到我是如何將jQuery代碼附加到視圖元素的。拖動本身非常完美,停止功能也被調用。
Scrum.Sortable = Ember.View.extend({
tagName : 'div',
didInsertElement: function(){
this.$().sortable({
placeholder: "ui-state-highlight",
stop:function(){
var order = 1;
$('div.pb-item').children().each(function(index){
$(this).find('.order').each(function(){
//
// Access and save the model here
//
$(this).html(order++);
});
});
}
});
}
});
你也可以看到我手動更新視圖html。這是我想在模型中存儲的內容。不幸的是,我似乎無法訪問該模型。
任何想法如何做到這一點非常感謝。
謝謝。
你能提供一個JSbin嗎? – Edu
似乎我不能。並非所有庫都可用,而且我似乎無法從其他位置加載它們。 – rbevers
在這個頁面中有JSBin和JSFidle的ember的起點http://stackoverflow.com/tags/ember.js/info – Edu