简体   繁体   English

createRecord之后如何检测Ember.js中的关系更改

[英]How to detect relation change in Ember.js after createRecord

I have 我有

Ember.computed("task.inputValues.[]", ..

Inside this method at certain condition, i trigger creation of new inputValues that have a task set with belongsTo . 在某些条件下,在此方法内,我触发创建新的inputValues,这些新的inputValues的任务设置为EmiratesTo But after records and relations are successfully set in Ember database (using " createRecord "), " task.inputValues.[] " does not catch/trigger computed method to recalculate? 但是在Ember数据库中成功设置了记录和关系之后(使用“ createRecord ”),“ task.inputValues。[] ”不捕获/触发计算方法来重新计算吗?

As Acorncom mentioned " folks recommend avoiding computed properties with side effects (such as creating new records) " 正如Acorncom所说:“ 人们建议避免使用带有副作用的计算属性(例如创建新记录)

Seems there is some kind of protection in Ember that prohibits recursive triggering of computed property by itself. 似乎Ember中存在某种保护,它本身禁止递归触发计算属性。

The solution was to move records creating code from computed property to Observer, after new records got inserted by the observer, computed property selector "task.inputValues.[]" did trigger. 解决方案是将创建代码的记录从计算属性移到观察者,观察者插入新记录后,触发计算属性选择器“ task.inputValues。[]”。

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

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