클릭하면 패널이 다시 렌더링되기를 원합니다. 내가 클릭을 수행 할 때backbone.js의 바인드 컨텍스트 전달
그러나, 나는 다음을 얻을 :
_callbacks: Object
_changed: true
_escapedAttributes: Object
_previousAttributes: Object
attributes: Object
cid: "c0"
collection: r.d
id: "f5589ba4-a0aa-dd86-9697-30e532e0f975"
__proto__: n
I :
Uncaught TypeError: Cannot call method 'get' of undefined
이 "이"내가 로깅하고있어 그 사실은 모델 자체 않은 것 같습니다 내 컨텍스트를 model.bind에 전달하여 적절한 "this"가 보존되지 않는 이유를 알아내는 데 문제가 있습니다.
// Models
window.Panel = Backbone.Model.extend({
defaults: function(){
return {
flipped: false,
};
},
toggle: function(){
this.save({flipped: !this.get("flipped")});
},
});
// Collections
window.PanelList = Backbone.Collection.extend({
model:Panel,
localStorage: new Store("panels"),
flipped: function(){
return this.filter(function(panel){ return panel.get("flipped"); })
}
});
// Global collection of Panels
window.Panels = new PanelList;
// Panel View
window.PanelView = Backbone.View.extend({
tagName: 'div',
template: _.template($("#panel-template").html()),
events: {
"click" : "toggle"
},
initialize: function(){
this.model.bind("change", this.render, this)
$(this.el).html(this.template(this.model.toJSON()));
},
render: function(){
console.log(this);
var flipped = this.model.get("flipped")
if (flipped){
$(this.el).addClass("flip");
} else{
$(this.el).removeClass("flip");
}
return this
},
toggle: function(){
this.model.toggle();
}
});
Flawless. 너 규칙. – nottombrown