我正在使用骨幹和木偶,骨幹收集比較器
我想對我的收集和渲染視圖進行排序。
但有些奇怪的事情發生。
'/ 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加載後掛鉤事件? –