Meteor 프로젝트에서 Session 변수를 동적으로 업데이트하는 모델을 작성하려고합니다. 나는 일반 JSON 백본 모델에 저장되지 않아야 함을 알고, 그래서 나는과 같이 설정 특별 모델이 있습니다백본 모델에서 '변경'이벤트는 어떻게 처리됩니까?
"가격"과 "날짜"와initialize : function() {
// Log the changed properties
this.on('change', function (model, options) {
for (var i in options.changes)
this.display(i);
Session.set('NewSpecial', model);
});
},
//Attributes
defaults: {
"Product" : null,
"ShortDescription" : null,
"Category" : "food",
"Price" : new PriceModel,
"Date" : new DateModel,
"Uses" : 0,
"Tags" : [],
"Contributor" : null
},
가 자신의 모델에 저장되는 :
//Price model for use within Special
var PriceModel = Backbone.Model.extend({
defaults : {
"Regular" : null,
"Special" : null,
"PercentOff" : null
}
});
//Date model for use within Special
var DateModel = Backbone.Model.extend({
defaults : {
"StartTime" : null,
"EndTime" : null,
"HumanTimeRange" : null
}
});
을
그림과 같이 특수 모델의 속성이 변경되면 변경된 속성에 대한 표시를 호출 한 다음 세션 var를 모델로 설정해야합니다. 그러나 DateModel 또는 PriceModel이 변경되면 Special 모델에서 변경 이벤트가 트리거되지 않습니다. 각 "DateModel"및 "PriceModel"은 this.on('change', ...)
메서드를 가지고 Special.set(attribute, thisModel)
메서드를 호출해야합니까? 아니면이 문제를 해결할 다른 방법이 있습니까?