简体   繁体   English

Ember.computed.equal在相同的字符串上返回false

[英]Ember.computed.equal returns false on identical strings

Is there something I don't understand or have I encountered a bug? 有什么我不明白或我遇到过的错误吗?

isCreator: Ember.computed.equal('session.user.id', 'model.user.id'), //false
isCreator2: Ember.computed('session.user.id','model.user.id', function() {  //true
    return this.get('session.user.id') === this.get('model.user.id');
}),

Ember.computed.equal doesn't take two property keys, it takes one property key and one constant value. Ember.computed.equal不带两个属性键,它需要一个属性键和一个常量值。 Taken from the documentation : 取自文档

A computed property that returns true if the provided dependent property is equal to the given value. 一个计算属性,如果提供的依赖属性等于给定值,则返回true。

If you want to compare two different properties you'll have to write the computed property manually like you've done with idCreator2 . 如果要比较两个不同的属性,则必须像使用idCreator2一样手动编写计算属性。

You can use ember-awesome-macro's equal instead, which takes two property keys. 您可以使用ember-awesome-macro相等,它需要两个属性键。 See https://github.com/kellyselden/ember-awesome-macros#equal . 请参阅https://github.com/kellyselden/ember-awesome-macros#equal

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

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