What is the difference between the '[]' property and the '@each' property in ember.js?

后端 未结 1 964
北海茫月
北海茫月 2021-02-04 03:14

I\'ve noticed that the enumerable mixin has computed properties that depends on the \'[]\' property, while ember arrays also have the \'@each\' propert

相关标签:
1条回答
  • 2021-02-04 03:37

    Use @each if you need to observe properties of array elements

    @each supports observing properties of the elements inside the array. For example, people.@each.name. The bracket notation does not support this. Here is a jsbin demo.

    @each is a property of Array instances that returns an EachProxy instance that handles the delegation. On the other hand, [] simply returns this.

    Use [] if you need it to work on non-Array enumerables

    According to the ember changelog, the bracket notation was made defunct in favor of @each in ember 0.9.4, but then re-enabled in 0.9.8. The commit that re-enables it indicates that [] can be used for non-Array enumerables such as Ember.Set instances. jsbin demo.

    0 讨论(0)
提交回复
热议问题