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