我正在尝试让路由的模型挂钩返回一些数组,该数组通过使用Emberlater
的轮询机制不断更新。路由文件如下所示:
export default class IndexRoute extends Route {
recent: [],
init() {
...
this.getRecent();
}
getRecent() {
// poll data / fetch latest
this.recent.push(newStuff);
later(this, this.getRecent, 2000);
}
model() {
return this.recent;
}
}
然后在我的控制器中,我想根据路由创建一个@computed
/属性:@tracked
model
export default class IndexController extends Controller {
// @tracked model; // this also didn't work
@computed('model.@each') // this doesn't work
get computedModel() {
console.log('computedModel'); // prints only once, when the model hook is first run
return this.model;
}
}
我认为这篇 SO 帖子的建议会奏效,但它没有:(
我看到了这篇文章,但这是针对 Ember 1.13 的,因此不完全是现代解决方案。
同样,这篇文章也有过时的内容。
我正在尝试做的事情可能吗?或者,我正在考虑将数据移动到控制器中,并改为创建控制器变量的计算属性。采纳所有建议!