Ember 为 "not equal to current route" 计算 属性
Ember computed property for "not equal to current route"
好奇下面计算的等同于做什么属性。事实上,Ember 的 computed.
并没有内置 notEqual 方法
isNotPizza: computed.notEqual('controllers.application.currentRouteName', 'pizza'),
使用自定义计算 属性:
isNotPizza: computed('controllers.application.currentRouteName', function () {
return 'pizza' !== this.get('controllers.application.currentRouteName');
}),
有几种方法:
import { not, equal } from '@ember/object/computed';
// ...
isPizza: equal('controllers.application.currentRouteName', 'pizza'),
isNotPizza: not('isPizza'),
或者,您可以通过以下方式使不等于:
import { not, equal } from '@ember/object/computed';
isNotPizza: not(equal('controllers.application.currentRouteName', 'pizza')),
虽然可能需要使用它:https://github.com/kellyselden/ember-macro-helpers如果本机支持,请不要删除ember。
如果你碰巧在 ember-canary(使用原生 类 和装饰器),你可以这样做:
@not
@equal('controllers.application.currentRouteName', 'pizza')
isNotPizza;
好奇下面计算的等同于做什么属性。事实上,Ember 的 computed.
并没有内置 notEqual 方法isNotPizza: computed.notEqual('controllers.application.currentRouteName', 'pizza'),
使用自定义计算 属性:
isNotPizza: computed('controllers.application.currentRouteName', function () {
return 'pizza' !== this.get('controllers.application.currentRouteName');
}),
有几种方法:
import { not, equal } from '@ember/object/computed';
// ...
isPizza: equal('controllers.application.currentRouteName', 'pizza'),
isNotPizza: not('isPizza'),
或者,您可以通过以下方式使不等于:
import { not, equal } from '@ember/object/computed';
isNotPizza: not(equal('controllers.application.currentRouteName', 'pizza')),
虽然可能需要使用它:https://github.com/kellyselden/ember-macro-helpers如果本机支持,请不要删除ember。
如果你碰巧在 ember-canary(使用原生 类 和装饰器),你可以这样做:
@not
@equal('controllers.application.currentRouteName', 'pizza')
isNotPizza;