collection.length
에 대한 템플릿을 인식하려면 listView.template
에 값을 전달해야합니다.
나는이 방법으로 매개 변수를 전달하기 위해 serializeData 메서드를 재정의하는 것이 하나의 방법이라고 생각한다. 나는 app
를 시작하면CompositeView에서 SerializeData
var ListView = Marionette.CompositeView.extend({
initialize: function() {
this.collection.on('reset', this.serializeData, this);
this.collection.on('remove', this.serializeData, this);
this.collection.on('add', this.serializeData, this);
},
serializeData: function() {
console.log(this.collection.length);
return {
has_tasks: this.collection.length > 0
};
},
// other codes
});
collection
그래서 아직 인출되지 않습니다 : 예상대로
1.A)을 collection.legth = 0
2.B) 템플릿 has_tasks = false
를 얻을. 템플릿는 has_tasks = false
2.A )는 collection.length is > 0
,
2.B)이 serializeData
가 호출을 가져오고 그래서 그것은 has_tasks = true
,
2.C두고
아무 아이디어 나 가지고 있기 때문에 2.c
? 보기에는 영향을 미치지 않습니다 다시 serializeData를 호출
var ListView = Marionette.CompositeView.extend({
initialize: function() {
this.bindTo(this.collection, 'reset', this.render)
},
serializeData: function() {
return { has_tasks: this.collection.length > 0 }
}
});
:
송신 지점 hasTask는 'hasTask = false'인 경우에 대한 템플릿 섹션을 표시합니다. 나는 뭔가 다른 것을 만들어야 할까? IMH CompositeView 템플릿에는 컬렉션에 대한 액세스 권한이 없으며 모델 속성 만 있습니다. 해당 항목은 컬렉션에 액세스 할 수 있습니다. 내가 맞습니까? –
합성보기 템플릿에서'console.log (this)'로 확인할 수 있습니다. 내가 당신과 같은 스택을 사용하지 않기 때문에 당신이 가지고있는 것을 확신 할 수 없습니다. –
CompositeView는 콜렉션에 접근 할 수 있지만'marionette.composed.view'는 콜렉션이없는'model.attributes'를 렌더링합니다. –