Ember.js 在EmberJS中自动计算组件

Ember.js 在EmberJS中自动计算组件,ember.js,ember-data,Ember.js,Ember Data,我试图在Ember中创建一个组件,显示一篇文章有多少评论。我从API中提取注释。现在的问题是,如果有新的注释,它不会重新查询API 有没有办法让Ember组件每隔15秒左右自动检查一次新注释以更新计数?可以在init hook中调用一个方法,该方法触发新注释获取,并在15秒过去时自行调用 commentsCount: Ember.computed.alias('comments.length'), // Use in template for items count init: functio

我试图在Ember中创建一个组件,显示一篇文章有多少评论。我从API中提取注释。现在的问题是,如果有新的注释,它不会重新查询API

有没有办法让Ember组件每隔15秒左右自动检查一次新注释以更新计数?

可以在init hook中调用一个方法,该方法触发新注释获取,并在15秒过去时自行调用

commentsCount: Ember.computed.alias('comments.length'), // Use in template for items count

init: function() {
    this._super(...arguments);
    this.getNewComments();
},

getNewComments: function() {
    Ember.run.later(() => {
        this.get('store').query('comments', { post: this.get('post.id') }).then(newItems => {
          this.get('comments').pushObjects(newItems);
          this.getNewComments(); // Calls itself out
       });
    }, 15000);
}
可以在init hook中调用一个方法,该方法触发新的注释获取,并在15秒过去时自行调用

commentsCount: Ember.computed.alias('comments.length'), // Use in template for items count

init: function() {
    this._super(...arguments);
    this.getNewComments();
},

getNewComments: function() {
    Ember.run.later(() => {
        this.get('store').query('comments', { post: this.get('post.id') }).then(newItems => {
          this.get('comments').pushObjects(newItems);
          this.getNewComments(); // Calls itself out
       });
    }, 15000);
}

由于ember.observer()相当重,因此它的可能副本确实比我提供的解决方案好得多。此外,它还执行OP要求的每15秒检查一次的操作。这确实比我提供的解决方案好得多,因为ember.observer()相当重。此外,它会按照OP的要求每15秒检查一次。。。