I'm using backbone and marionette,
and I want to sort my collection and rendering view.
but something weird happening.
'/api/note/getList', it returns (and it called when collection be initialized by view)
[{"id":22,"name":"Test2","isPublic":1},{"id":11,"name":"Test1","isPublic":1},{"id":33,"name":"Test3","isPublic":1}]
and this is my collection,
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'
and the console.log print
22
22
11
print '22' twice? also it does not sorting neither.
How should I do to make sorting the collection?
[EDIT]
This is my compisteView that initialize collection
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 = new NoteCollection() => this run fetch automatically i think.