【发布时间】:2016-06-11 18:39:53
【问题描述】:
我有以下场景:
我从数据库(meteor/mongo)加载一些东西,例如与:
this.subscribe('cards', options, () => {
this.cards = Cards.find({}, {sort: this.sortObject.get()});
}, true);
在模板中,我使用 *ngFor="#card of cards" 遍历这些项目
当我在某个动作上扩展对象时,例如
this.cards.forEach((card:Card) => {
card.distance = someValue;
});
模板没有更新,即当我使用{{card.distance}}时,它不显示。
是否无法使用流星和角度 2 扩展订阅的对象/列表?
【问题讨论】:
-
在
forEach之后尝试this.cards=this.cards.slice(); -
感谢提示,我试过了,但得到了错误
Property 'slice' does not exist on type 'Cursor... -
如果
forEach不是数组,如何迭代? -
它是一个流星/mongo 光标,显然有 forEach 但没有切片
-
是否有
toArray()。这可能也会起作用。