有没有办法在余烬存储中的任何余烬模型更改上设置观察者? [英] Is there a way to set an observer on any ember model change in ember store?

查看:68
本文介绍了有没有办法在余烬存储中的任何余烬模型更改上设置观察者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我正在使用ember2。
我正在请求后端,它返回一些数据。然后,我将这些数据推送到灰烬存储中的模型。更新此模型后,我想执行一些操作的问题。那么,有没有办法在商店中观察模型?
预先谢谢您。

First of all, I am using ember 2. I am requesting the back-end and it returns some data. 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 返回实时数组,因此我们可以为findAll结果使用相关键,以便每次存储模型更改时都会触发观察者/计算属性。

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.

 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.

这篇关于有没有办法在余烬存储中的任何余烬模型更改上设置观察者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆