我正在使用Tracker.autorun中的fetch()将Mongo.Cursor转换为数组并将其分配给songsArray
。但每次更改基础数据库(被动)时,我都会在songsArray
private songsArray:Array<any>;
songsCursor:Mongo.Cursor<any>;
//...Some code here
ngOnInit():any {
//... Some code here
this.songsCursor = Songs.find();
Tracker.autorun(() => {
this.songsArray = [];
this.songsArray = this.songsCursor.fetch();
});
}
为什么会发生这种情况,如果我认为我做错了,那么在Tracker.autorun
中将游标转换为数组的正确方法是什么?
答案 0 :(得分:0)
在你的构造函数中,你需要做这样的事情:
$reactive(this).attach($scope);
// Subscribe to collections here:
this.subscribe('songs');
this.helpers({
songs: () => Songs.find()
});
并且您会发现歌曲是您想要的数组