처럼되고 싶지 않아. 그래서이 예제에서는 이름과 선택적 콜렉션이있는 모델을 설정했습니다. 콜렉션이 사용되면 선택적 콜렉션을 가질 수있는 모델 콜렉션이 포함됩니다.
다음 컬렉션보기를 정의하면 컬렉션보기에서 자식 컬렉션이 있는지 확인하고 컬렉션 뷰가 자식으로 컬렉션보기를 사용합니다.
//collection view that can choose to display another collection view or a model
myApp.Views.View1 = Marionette.CollectionView.extend({
tagName: "ul",
//overridden getChildView to return either another collection view or an item view
getChildView: function (child) {
if (child.get("collection")) {
return myApp.Views.View1;
}
return myApp.Views.ItemView;
},
//set either the collection or the model depending which view we are using
childViewOptions: function (model, index) {
if (model.get("collection")) {
return {
collection: model.get("collection"),
}
} else {
return {
model: model
}
}
}
});
그 다음에 그냥 모델
//item view to display final model
myApp.Views.ItemView = Marionette.ItemView.extend({
tagName: "li",
template: _.template('<%= name %>'),
})
여기
실행중인 표시 할 항목보기를 사용하지 않는 경우 - 당신의 이름을 표시하고 싶었 http://jsfiddle.net/leighking2/r5ogoL5h/
에게 모델을 컬렉션 위에 렌더링하면 컴포지트 뷰를 사용할 수 있으므로 컬렉션을 표시하기 위해 뷰에 연결하여 더 많은 제어를 허용합니다.
,210
http://jsfiddle.net/leighking2/kx9kuup0/
유일한 문제는, 아직 렌더링 당신이 복합 내부보기 만 해결 될 수 일부 조정과 복합보기를 표시 할 때 이중 <ul>
와 끝까지 같이 HTML이 100 % 유효하다 올바르게.
저는 A, B, C에 대한 각각의 뷰, 즉 뷰가 서로 다른 상당히 복잡한 구조를 가지고 있습니다. 처리 할 이벤트가 많습니다. 정렬 기능을 원합니다 (정렬 버튼을 클릭하면 DOM을 정렬해야 함).). 내가 어떻게 할 수 있니? – pratiksanglikar
소스 코드 예제가 있습니까? –