所以我在我的 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) 上。
我真的不确定为什么,任何有关如何调试的建议都会有所帮助。我不认为我在这里做了任何疯狂或不寻常的事情。