2012-10-21 9 views
1

저는 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()}); 
} 


}); 

그래서 페치가 작동하는 것 같다,하지만 어떻게 속성이 액세스 할 수 있습니까?

+0

getRecord에서 호출되는 this.anzeige는 무엇입니까? 나는 그것이 어디에서나 정의 된 것을 볼 수 없다. 정말로 this.model의 fetch 메소드를 호출해야합니다. –

+0

'console.log (self.model);'에서 볼 수있는 값을 공유 할 수 있습니까? 위의 주석에 동의합니다.'model.fetch()'메소드를 호출하지 않기 때문에 가져온 값이'self.model'에 저장되지 않습니다. –

+0

console.log가 작동한다고 말하면 모델이 Object로 기록 된 것을 볼 수 있으며이 객체에는'attributes' 속성이 있으며이 속성에는'title'이라는 속성이 있습니까? – Tallmaris

답변

0

"callback()"을 "callback"으로 변경하여 지금 작동시킬 수 있습니다.

+0

나는 아직도 그것을 얻지 않는다. 어떻게 매개 변수를 콜백 함수에 전달할 수 있습니까? 나 또한 cordova.js와 함께 이것을 실행하려고했지만 콜백 함수가 실행되지 않는다. – ilse2005