我有一个木偶项目视图,它在页面的两个位置呈现。让我们举一个像外国地址和本地地址的例子。由于两个字段相同,我们使用相同的视图只是标题标签的更改。
我们对两个地址都有单独的保存,并且在数据库中也有两个条目。保存后,我们将渲染视图。
问题如下
我正在考虑以下可能性
如果没有单独的观点,请告诉我这个问题的任何解决方案。
代码:
收藏视图:
define(
["marionette",
"address/views/sampleAddressEmptyView",
"address/views/sampleAddressItemView",
"address/views/sampleAddressLayoutView"],
function(Marionette,
sampleAddressEmptyView,
sampleAddressItemView,
sampleAddressLayoutView){
return Marionette.CompositeView.extend({
template: "templates/sampleAddresses.hbs",
initialize: function(options){
this.mergeOptions(options,this.collections);
}
collections: ['districts'],
childView: sampleAddressItemView, //Initially I had a layout view even though I changed to item View, still both views are rendering on saving of other view
emptyView: sampleAddressEmptyView,
childViewContainer: '#addresses',
childViewOptions: function(){
return {
collection: this.collection,
districts: this.districts
};
}
});
});
LayoutView:
return Marionette.LayoutView.extend({
.
.
.
isEditable: false,
getTemplate: function() {
return this.isEditable ? 'templates/editAddress.hbs':'templates/displayAddress.hbs';
},
regions:{
districtRegion:'#districtRegion'
},
initialize:function(options){
this.mergeOptions(options,this.viewOptions);
//this.collection.models having two records
},
viewOptions: ['districts'],
onRender: function () {
if(this.isEditable === false){
return;
}else if((this.isEditable) || this.mode === 'create'){
this.renderRegions();
}
},
renderRegions: function(){
.
.
.
},
templateHelpers: {
.
.
}
ItemView控件:
I tried changing the above Layoutview to ItemView (Removed the regions block of layoutview), still the problem is persisting.
如果我在代码中缺少任何内容,请告诉我。