双重条件#if [英] Double condition with #if

查看:152
本文介绍了双重条件#if的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何做双重条件{{#if person&&工作}}?
&&&似乎不是一个有效的运算符

How to do a double condition {{#if person && work}} ? The && seems not a valid operator

推荐答案

我不相信handlebars支持{{#if}}语句中的多个项目:逻辑运算符在一个handlebars.js {{#if}}条件)。

I don't believe handlebars supports multiple items in the {{#if}} statement (related: Logical operator in a handlebars.js {{#if}} conditional).

您可以将控制器/视图中的多个值折叠为单个计算属性,并检查模板中的单个值。这个新的计算属性将在任何一个原始值更新时更新:

You could collapse the multiple values in your controller/view into a single computed property and check that single value in the template. This new computed property will update when either of the original values update:

App.ValuesTestController = Ember.Controller.extend({
    value1: false,
    value2: true,
    value1and2: function(){
            return this.get('value1') && this.get('value2');
    }.property('value1', 'value2')
});

您的模板如下所示:

<div>{{#if value1 }}value 1 true{{/if}}</div>
<div>{{#if value2 }}value 2 true{{/if}}</div>
<div>{{#if value1and2 }}value 1 and 2 true{{/if}}</div>

这篇关于双重条件#if的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆