简体   繁体   English

有没有办法在余烬存储中的任何余烬模型更改上设置观察者?

[英]Is there a way to set an observer on any ember model change in ember store?

First of all, I am using ember 2. I am requesting the back-end and it returns some data. 首先,我正在使用ember2。我正在请求后端,它返回一些数据。 Then, I pushed these data to a model in ember store. 然后,我将这些数据推送到灰烬存储中的模型。 The issue that I want to do some action when this model is updated. 更新此模型后,我想执行一些操作的问题。 So, Is there a way to observe the model in the store? 那么,有没有办法在商店中观察模型? Thank you in advance. 先感谢您。

findAll returns live array, so we can have dependent key for the findAll result so that our observer/computed properties will be triggered every time stores model changes. findAll返回实时数组,因此我们可以为findAll结果使用相关键,以便每次存储模型更改时都将触发我们的观察者/计算属性。

 userModel:Ember.computed(function() {
    return this.get('store').findAll('user');
  }),

 userModelObserver: Ember.observer('userModel.[]',function(){
    console.log('observer triggered');
  }),

May be this is not the ideal solution. 可能这不是理想的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM