所以我在AppView中这样做
var flowerModel = new app.DataModel({title: "flower", values: ["tulip","rose","dandelion"], dataToShow:["tulip", "rose", "dandelion"], data: data});
var timelineModel = new app.TimeChartModel({data: flowerModel.getDisplayedData(), titlesToShow: flowerModel.get('dataToShow')});
tableCollection.add(flowerModel);
var timechart = d3.select("body").append("div").attr("class","timechart");
this.centerView = new app.TimeChartView({model: flowerModel, el : timechart});
this.rightView = new app.TableView({model: flowerModel});
在我的TimeChartView init方法中,我这样做 -
initialize: function(){
this.model.bind('change','render');
//other, irrelevant things
}
并且在我的flowerModel中我有这个方法,当勾选一个复选框时它会起作用 -
events: {
'click .data-type' : 'collapseDatum',
'click .show-datum' : 'addDatumToShow',
},
addDatumToShow: function(e){
var test = $(this.$el).find(".datum-list").find(":checked");
newDataToShow = [];
_.each(test, function(value,key,list){
var title = $(value).data("title");
newDataToShow.push(title);
});
this.model.set("dataToShow", newDataToShow);
},
错误发生在this.model.set('dataToShow',newDataToShow)上。
我真的不确定为什么,关于如何调试的任何建议都会有所帮助。我不认为我做了什么疯狂,或者在这里不寻常。
答案 0 :(得分:1)
试试这个:
flowerModel.bind('change:dataToShow', function() {
timelineModel.set('titlesToShow', flowerModel.get('dataToShow'));
});
this.model.bind('change', this.render);