我有一个这样的地图:
var AppState = can.Map.extend({
sites: null
});
appstate = new AppState();
列表填充如下:
Site.findAll({}, function(sites) {
appstate.attr('sites', sites);
});
我将其传递给这样的控件:
new SummaryCtrl("#summaryCtrl", {sites:appstate.compute('sites')});
控件如下所示:
var SummaryCtrl = can.Control.extend({
'{sites} change': function(ev, type, sites) { //this doesn't fire
var recent = sites.slice(0,25);
var siteCount = sites.length;
this.element.html(can.view('summaryTpl', {siteCount:siteCount, recent:recent}));
}
});
然后我这样做:
var newsite = {blah1:'blahblah', blah2:'blahblah'};
appstate.sites.unshift(newsite);
但是“{sites} change”功能不会触发。知道为什么吗?谢谢!