我不明白爲什麼this.model將在view.intialize()中定義,當我運行this.model.fetch(),而不是在view.render()。骨幹模型未定義?
define([
'jquery',
'underscore',
'backbone',
'text!templates/example.html'
], function($, _, Backbone, exampleTemplate){
var exampleView = Backbone.View.extend({
el: $('body'),
initialize: function() {
this.model.set({ _id: this.options.user_id });
this.model.fetch({
success: this.render,
error: function(model, response) {
console.log('ERROR FETCHING MODEL');
console.log(model);
console.log(response);
}
});
},
render: function() {
console.log('HELLO FROM RENDER');
console.log(this.model);
console.log('GOODBYE FROM RENDER');
}
});
return exampleView;
});
成功被調用時'this'被取消引用嗎?也許你需要綁定它。 – JaredMcAteer 2012-01-10 16:46:04