使用 http://www.lukemelia.com/blog/archives/2012/03/10/using-ember-js-with-jquery-ui/我正在尝试在由 Ember.ArrayController 加载的模板中实现一个可排序列表,该模板包含一个电话号码数组作为内容:
{{#collection App.SortableListView contentBinding="phonenumbers" itemViewClass="App.SortableItem"}}
<b>{{phonenumber.cost}}</b>
{{/collection}}
我试图在排序后更新每个电话号码的“顺序”属性,但我不知道该怎么做:
App.SortableListView = JQ.SortableListView.extend({
items: 'article',
//update is a jquery ui method called when the sort ends and dom has been updated
update: function(event, ui) {
// I would like to update and persist each phonenumbers model here
}
});
我尝试了各种方法:按顺序绑定(bind)属性,通过 jquery 的数据属性,使用每个 childView 的 contentIndex 属性(但在排序时它没有更新)...一切都失败了,或者对于这样一个简单的事情来说太复杂了。
我想我遗漏了一些明显的东西,感谢您的帮助。
最佳答案
数组 Controller 上有 sortProperty 方法可以做你想做的事
关于javascript - 将 jquery-ui 与 ember.js 一起使用时更新 ArrayController 模型中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16041672/