【发布时间】:2018-05-11 19:27:47
【问题描述】:
我有两个条件需要检查禁用按钮的情况。
示例代码,我的做法
<div class="{{if isallowed 'notallowed'}} {{if isloading 'notallowed'}}">Submit</div>
谢谢。
【问题讨论】:
标签: ember.js handlebars.js htmlbars
我有两个条件需要检查禁用按钮的情况。
示例代码,我的做法
<div class="{{if isallowed 'notallowed'}} {{if isloading 'notallowed'}}">Submit</div>
谢谢。
【问题讨论】:
标签: ember.js handlebars.js htmlbars
你可以这样做:
<div class={{unless isallowed 'notallowed' (if isloading 'notallowed')}}>Submit</div>
【讨论】:
我喜欢在一般情况下使用ember-truth-helpers:
{{#if (and foo bar)}} foobar! {{/if}}
对于调整类(仅限组件),我使用classNameBindings。
classNameBindings: [isUrgent]
如果在组件上下文中 isUrgent 为真,这将向组件添加类 is-urgent。
【讨论】:
我们可以通过使用 helper 来实现。
我为此创建了助手,并且对我来说工作正常。
助手'isany-true'
import Ember from 'ember';
export function anytrue(params) {
return params.includes(true)
}
export default Ember.Helper.helper(anytrue);
示例
<div class="{{if (isany-true isdisableprev isloading) 'notallowed'}}">Submit</div>
【讨论】:
class={{if (or isdisableprev isloading) 'notallowed'}} 。