我是backbone.js 的新手,我被一个简单的任务困住了。
我想从数据库中获取记录并将其放入模型中。获取似乎有效,但我无法获取模型属性。这是我的代码:
我的模型:
window.Model = Backbone.Model.extend({
url: "mobile-rest/get-anzeige",
initialize:function () {
},
});
我的观点:
window.Page = Backbone.View.extend({
initialize:function () {
this.template = _.template(tpl.get('page'));
},
render:function (eventName) {
var self = this;
this.getRecord(function(resp){
$(self.el).append(self.template({model: self.model}));
console.log(self.model); //works and I see the right values in the console
console.log(self.model.title); //is undefined
console.log(self.model.get('title'); //also undefined
});
return this;
},
getRecord: function(callback){
this.model= new Model({id: this.id});
this.model.fetch({data: $.param({id: this.id}), success: callback()});
}
});
所以获取似乎工作,但我怎样才能访问属性?