ste*_*iel 8 javascript conditional templates handlebars.js ember.js
在ember中使用条件时,是否可以有一个OR?
{{#if foo OR bar}}
Run Code Online (Sandbox Code Playgroud)
要么
{{#if foo || bar}}
Run Code Online (Sandbox Code Playgroud)
文档中似乎没有任何内容.
Kin*_*n2k 14
您应该将逻辑移动到控制器
App.SomeController = Em.Controller.extend({
foo: true,
bar: false,
fooOrBar: Em.computed.or('foo', 'bar')
});
Run Code Online (Sandbox Code Playgroud)
将模板逻辑保持在最低限度
{{#if fooOrBar}}
Run Code Online (Sandbox Code Playgroud)
Max*_*ace 12
使用https://github.com/jmurphyau/ember-truth-helpers:
ember install ember-truth-helpers
Run Code Online (Sandbox Code Playgroud)
然后你可以说
{{#if (or foo bar)}}
Run Code Online (Sandbox Code Playgroud)
根据您的观点,Kingpin2k的答案有点过时了.以前,社区的理解是模板应该基本上没有逻辑.加班,我们的观点已转向在模板中加入更多的声明性逻辑 - ember-composable-helpers就是一个很好的例子.
| 归档时间: |
|
| 查看次数: |
6021 次 |
| 最近记录: |