我遇到了很多例子,其中骨幹視圖將像var view1 = Backbone.View.extend({ })
但無法獲得一個骨幹視圖直接返回。在下面的代碼中,我可以呈現模型屬性的默認值,並在灰塵模板中顯示相同的內容,但當我做model.fetch()
時,在成功函數中,我能夠在控制檯中看到json響應,但無法設置將值提取到模型屬性並呈現新值。是的,讓我知道我在這裏想念的是什麼。任何幫助表示讚賞。無法設置骨幹模型屬性後model.fetch()調用
define(function (require) {
'use strict';
var $ = require('jquery');
var Backbone = require('backbone');
var g = require('global/dust-globals');
var template = require('text!/dust/table1.dust');
var SampleModel = Backbone.Model.extend({
initialize: function() {
},
defaults:{
SampleUpdate:'Test date',
SampleCount: 0
},
urlRoot: "/Sample"
});
var obj1 = new SampleModel();
return Backbone.View.extend({
events: {
// 'click .search-btn': 'searchBtnClick',
},
initialize: function(){
this.testfunc();
this.render();
this.model.on("change", this.render, this);
},
render: function() {
this.$el.html(g.renderTemplate('TabView', template, {}));
//template is compiled and rendered successfully
console.log('CHECK:'+obj1.get("lastUpdate"));
return this;
},
testfunc : function() {
obj1.fetch({
success: function (response) {
console.log(JSON.stringify(response));
obj1.set("SampleUpdate", response.get("sampleUpdate"));
obj1.set("SampleCount", response.get("sampleCount"));
console.log('CHECK1:'+obj1.get("SampleUpdate"));
}
});
}
});
});
我的JS代碼調用上面的代碼將如下。
var TabView = require('/SampleTab');
return Backbone.View.extend({
initialize: function() {
this.tabView = new TabView({el: '#sample-div', model:this.model, appView: this});
this.render();
},
render: function() {
this.tabView.$el.show();
this.tabView.render();
}
});
考慮改寫你的問題,目前尚不清楚 – mikeapr4
@ mikeapr4我已經改寫了這個問題..希望這有助於理解 –