저는 backbone.js에 익숙하지 않아 간단한 작업이 필요합니다.
데이터베이스에서 레코드를 가져 와서 모델에 넣고 싶습니다. 가져 오기가 작동하는 것처럼 보이지만 모델 특성을 가져올 수 없습니다. 여기 내 코드 :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()});
}
});
그래서 페치가 작동하는 것 같다,하지만 어떻게 속성이 액세스 할 수 있습니까?
getRecord에서 호출되는 this.anzeige는 무엇입니까? 나는 그것이 어디에서나 정의 된 것을 볼 수 없다. 정말로 this.model의 fetch 메소드를 호출해야합니다. –
'console.log (self.model);'에서 볼 수있는 값을 공유 할 수 있습니까? 위의 주석에 동의합니다.'model.fetch()'메소드를 호출하지 않기 때문에 가져온 값이'self.model'에 저장되지 않습니다. –
console.log가 작동한다고 말하면 모델이 Object로 기록 된 것을 볼 수 있으며이 객체에는'attributes' 속성이 있으며이 속성에는'title'이라는 속성이 있습니까? – Tallmaris