我正在使用骨干和木偶,骨干收集比较器
我想对我的收集和渲染视图进行排序。
但有些奇怪的事情发生。
'/ API/NOTE /的GetList',它返回(和它调用时收集通过视图进行初始化)
[{"id":22,"name":"Test2","isPublic":1},{"id":11,"name":"Test1","isPublic":1},{"id":33,"name":"Test3","isPublic":1}]
,这是我的收藏,
define [
'models/Note'
],
(Note) ->
class NoteCollection extends Backbone.Collection
model : Note
url : '/api/note/getList'
comparator : (item) =>
console.log item.get 'id'
return item.get 'id'
和console.log print
22
22
11
print'22'twice?也不排序。
我应该怎么做排序集合?
[编辑]
这是我compisteView是初始化集合
define [
'hbs!./noteCollection_tpl'
'./noteItemView'
'collections/NoteCollection'
],
(noteCollection_tpl, noteItemView, NoteCollection) ->
class NoteCollectionView extends Backbone.Marionette.CompositeView
template : noteCollection_tpl
itemView : noteItemView
itemViewContainer : '.noteListContainer'
className : 'noteWrap'
initialize : (options) ->
@collection = new NoteCollection()
@collection =新NoteCollection()=>这个自动运行,我认为获取。
如果您打印收集,订单是什么?比较函数用于对集合进行排序,因此查看它打印出的内容并不一定会给你订单。 – elevine
当集合被初始化时,url被调用。如何在URL加载后挂钩事件? –