Marionette.CompositeView
에서 컬렉션을 정렬하려고합니다.CompositeView에서 컬렉션을 정렬하는 가장 좋은 방법
[
{id: 1, name: 'bar'},
{id: 2, name: 'boo' },
{id: 3, name: 'foo' }
]
내가 역순 ID로 컬렉션을 정렬 할 필요
나는 다음과 같다 컬렉션이 있습니다.
실제로 페이지를 새로 고침 할 때만 작동합니다.
새 모델을 추가하면 새 항목이 목록에 임의로 추가됩니다.
페이지를 새로 고치면 잘 분류됩니다.
내 질문은 :
1) 새 모델을 추가 할 때 문제를 해결하는 방법?
2) 코드를 개선 할 수 있습니까? 당신이 컬렉션을 만들 때
return Marionette.CompositeView.extend({
initialize: function() {
this.collection.fetch();
},
onRender: function() {
var collection = this.collection;
collection.comparator = function (collection) {
return - collection.get('id');
}
},
onSuccess: function() {
this.collection.add(this.messageModel);
this.collection.sort(); // the messageModel seems to be added
// apparently randomly to the list.
// only if I refresh the page it will be ok
}
})
GitHub의 링크가 – ErichBSchulz
는 GitHub의 링크가 더 이상 죽은입니다 .. 아주 잘 작동 발견 됐어요 죽은. – Ziggy
Github의 링크가 다시입니다 :-) 죽은 :-( – abhaga