본인 및 백과 사전에 처음입니다. 이제 marioettejs의 compositeview로 페이징을 구현하려고합니다. 아래 코드는 내 사용자 정의 호출기를 통해 새로운 가져 오기가 수행 될 때 기존 데이터가 추가하는 대신 새로운 데이터 집합으로 대체된다는 것을 의미합니다. 이것을 극복하도록 도와주세요! 미리 감사드립니다.Backbone Marionette 복합 뷰를 사용하여 페이징을 수행하려면 어떻게해야합니까?
define(['text!/Templates/projects/_GroupItem.html', 'collections/projects/groups'], function (ProjectGroupsTmpl, GroupCollection) {
var GroupItemView = Backbone.Marionette.ItemView.extend({
tagName: 'li',
template: _.template(ProjectGroupsTmpl)
});
var CompositeView = Backbone.Marionette.CompositeView.extend({
template: _.template("<ul id='ulgroups' ></ul>"),
itemView: GroupItemView,
itemViewContainer: '#ulgroups',
initialize: function (params) {
this.isLoading = false;
this.ProjectID = params.id;
this.collection = new GroupCollection();
this.getData();
var self = this;
$(window).scroll(function() {
self.checkScroll();
});
},
getData: function() {
var that = this;
this.isLoading = true;
this.collection.fetch({
data: { ProjectID: this.ProjectID },
success: function (collection, response, options) {
that.isLoading = false;
}
});
},
checkScroll: function() {
var triggerPoint = 100; // 100px from the bottom
if (!this.isLoading && $(window).scrollTop() + $(window).height() + triggerPoint > $(document).height()) {
this.collection.page += 1; // Load next page
this.getData();
}
},
appendHtml: function (collectionView, itemView, index) {
$(this.itemViewContainer).append(itemView.el);
}
});
return CompositeView;
});
감사 스미스하지만, 뷰 자체 내부 수집을 가져하려는 경우 제안을해야합니까? –
여전히 마스터 컬렉션 (GroupCollection)에서 모델을 가져올 수 있습니다. 각 가져 오기에서 관련 모델을 임시 컬렉션에 추가하는 것입니다. 임시 수집은 비어있는 채로 시작하여 데이터를 새로 추가 할 때마다 추가됩니다. 이해가 되니? 데이터 요청 및 뷰 작성을 관리하는 컨트롤러를 만드는 것이 좋습니다. IMO에 대한보다 명확한 분리를 만듭니다. –