问题:当控制器修改“pages”数组时,计算属性“tnop”没有得到更新,如下所示:
相关书籍型号代码:
sections: []
tnop: function()
{
var n = 0;
var sections = this.get('sections');
if (!sections)
return n;
for (var i=0; i < sections.length; i++) {
n += sections[i].pages.length;
}
return n;
}.property('sections.@each.pages.length')
相关控制器代码:
var sections = EM.model.getPath('book.sections');
var aps = EM.model.getPath("ps");
$.each(sections, function(si, section) {
var bp = [];
if (json && json.ia) {
bp = section.get("pages");
var ns = aps[json.ssi];
var lp = ns.get("lp");
var rp = ns.get("rp");
if (rp) {
bp.insertAt(lp.number-1, rp);
bp[lp.number-1] = rp;
}
if (lp) {
bp.insertAt(lp.number-1, lp);
bp[lp.number-1] = lp;
}
}
});