0
我有一个模型和视图,将模型获取数据之前在那里视图渲染后取。当我检查数据库时,当我在视图中进行更改时,数值仍然保留在数据库中。但在视图渲染时,我无法通过model.fetch()获取值。模型数据撕心裂肺的观点
define([
"marionette",
"monet",
"modules/fetchParams/collections/fetchParamsListLevels",
"modules/fetchParams/views/fetchParamsLayoutView",
"modules/fetchParams/models/fetchParam"
], function(Marionette, Monet, fetchParamListLevels, FetchParamsLayoutView,FetchParamModel){
return Marionette.Module.extend({
model:"",
onStart:function(){
this.model =new FetchParamModel();
},
displayInRegionMarketParams:function(region){
this.fetchModel("market");
region.show(new FetchParamsLayoutView({model: this.model, title: " Market"}));
},
displayInRegionShareParams:function(region){
this.fetchModel("shares");
region.show(new FetchParamsLayoutView({model: this.model, title: "Shares"}));
},
.
.
.
fetchModel:function(type){
this.model.setType(type);
this.model.fetch();
}
我试过如下,但无法找到解决方案。让我知道我在这里失踪。
this.listenTo(this.model, "change", this.render());
感谢您的投入。我有一个关于怀疑model.fetch(),model.fetch后()完成,它被自动设定值模型。还有一件事我试图把我的区域获取的成功回调里面,有问题的区域为“区域为未定义” – CNKR
是,'model.fetch()'自动新的数据集模型,这样你就可以听在我的答案的第一部分中使用'listenTo'进行更改。 – Yura
同样区域可能恰好是不确定的,因为你失去的上下文,这意味着'this'是不是同一个对象实例了。 – Yura