Shorthand 计算属性

Shorthand computed properties

谁能解释一下为什么它们的计算结果不同?

Ember.ArrayController.extend({
    maxProducts: 5,

    hasMaxProducts: function () {
        return this.get('model.length') === this.get('maxProducts');
    }.property('model.length'),

    shorthandHasMaxProducts: Ember.computed.equal('model.length', 'maxProducts')
});

我在车把模板中成功使用了 hasMaxProducts 属性,如果我尝试切换到 shorthandHasMaxProducts 属性,我没有得到结果相同,属性 似乎也没有更新。当我将另一个模型添加到数组集合时,应该会发生这种情况。我也尝试过计算:

Ember.computed.equal('model.[]', 'maxProducts')
Ember.computed.equal('model.[].length', 'maxProducts')

Ember.computed.equal 的第二个参数不能是 属性 名称,它必须是普通的 javascript 值,因此可以是字符串、整数、布尔值等。

http://emberjs.com/api/#method_computed_equal