CompositeView가 정의 된 itemView로 데이터를 전달할 수 있는지 궁금합니다. 보기 (축소) 코드 :Backbone.Marionette : CompositeView를 통해 itemView로 데이터를 전달 하시겠습니까?
var TableView = Backbone.Marionette.CompositeView.extend({
template: '#table-template',
itemView: TableRowView,
itemViewContainer: 'tbody',
});
var TableRowView = Backbone.Marionette.ItemView.extend({
tagName: 'tr',
template: '#table-row-template',
serializeData: function() {
var data = {
model: this.model,
// FIXME This should really only be called once. Pass into TableView, and down into TableRowView?
// That way, getDisplayColumns can be moved to the collection as well, where it makes more sense for it to belong.
columns: this.model.getDisplayColumns()
};
return data;
}
});
두 가지를 사용하여 HTML 표를 렌더링합니다. # table-row-template에는 여러 유형의 "열"을 지원하는 일부 렌더링 논리가 있습니다. 이를 통해 다양한 유형의 컬렉션/모델 (API를 따르는 한)에서 동일한보기를 사용할 수 있습니다. 지금까지 꽤 잘 작동했습니다!
위에서 볼 수 있듯이, 각 "행"은 매번 같은 "열"데이터를 가져 오기 위해 전화를 걸었습니다. 실제로 그 데이터를 한 번만 전달하고 모두를 사용하고 싶었습니다.
권장 사항?
감사합니다.
감사합니다. 많은 감사합니다. 문서 도구는 업데이트로 수행 할 수 있습니다. – starmonkey
n.b. Marionette v2가'item *'을'child *'로 바꾸었다. – alxndr