[英]Observe change of object proprty in nested array in Ember.js
We have this data structure我们有这个数据结构
[[{foo:"12", bar:"34"}, {foo:"33", bar:"55"}], [{foo:"45", bar:"67"}]]
How is it possible to make a computed property to observe a change on foo
or bar
?如何创建一个计算属性来观察
foo
或bar
的变化?
Normally you use .@each.someProperty
in a computed property to watch specific object properties in an array but in the case of nested arrays (or nested objects), you can't do .@each.@each.someProperty
because .@each
only works one level deep.通常,您在计算属性中使用
.@each.someProperty
来查看数组中的特定 object 属性,但在嵌套 arrays (或嵌套对象)的情况下,您不能执行.@each.@each.someProperty
因为.@each
只能深一层。
You need to use intermediary computed properties to raise the inner objects up one (or more) levels and have another computed property watch these in turn.您需要使用中间计算属性将内部对象提升一个(或多个)级别,并让另一个计算属性依次监视这些。 There may be other ways to wire things up, but this is a pretty straightforward way to do it.
可能还有其他方法可以连接起来,但这是一种非常简单的方法。
Here's a twiddle that demonstrates it.这是一个证明它的旋转。 If you open the console you can see the individual computed properties recording a change occurring.
如果您打开控制台,您可以看到记录发生更改的各个计算属性。
You can also use an alias to pull the inner arrays / objects up a level or two.您还可以使用别名将内部 arrays / 对象提升一两级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.