How to implement not with if statement in Ember Ha

2019-03-08 06:40发布

I have a statement like this:

{{#if IsValid}}

I want to know that how can I use if statement with not like that:

{{#if not IsValid}}

6条回答
成全新的幸福
2楼-- · 2019-03-08 06:53

Simple answers for simple questions:

{{#unless isValid}}
{{/unless}}

Also keep in mind that you can insert an {{else}} in between an {{#if}} or {{#unless}} and the closing tag.

查看更多
一夜七次
3楼-- · 2019-03-08 06:53
{{#if items.length}}
    //Render
{{/if}}

Here items.length .. if it returns some value except null, then only it will enters into the if loop.

NOTE : You can check Boolean values also. In If block

{{#if booleanFloag}}
查看更多
祖国的老花朵
4楼-- · 2019-03-08 06:57

Below Statements Will help full if you want to use if and else :

{{#if author}}
    <h1>{{firstName}} {{lastName}}</h1>
{{else}}
    <h1>Unknown Author</h1>
{{/if}}

NOTE : Dont close the if Block until logic finished ...

查看更多
该账号已被封号
5楼-- · 2019-03-08 06:58

it can be done in multiple ways.

1 use unless

{{#unless IsValid}}
<Your Code>
{{/unless}}

2.use if else

{{#if IsValid}}
{{else}}
<Your Code>
{{/if}}

3.use not helper

{{#if (not IsValid)}}
<Your Code>
{{/if}}
查看更多
The star\"
6楼-- · 2019-03-08 07:17

unless block helper (built-in helper)

unless helper is the inverse of the if helper.

Its block will be rendered if the expression returns a falsy value.

  {{#unless valid}}
  <h3 class="warning">WARNING</h3>
  {{/unless}}
查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-03-08 07:19

You have many ways of doing that.

1. Use {{unless}}:

{{#unless isValid}}
  ...
{{else}}
  ...
{{/unless}}

2. Use inline-if helper:

{{#if (if isValid false true)}}
  ...
{{else}}
  ...
{{/if}}

3. Use ember-truth-helpers addon:

{{#if (not isValid)}}
  ...
{{else}}
  ...
{{/if}}
查看更多
登录 后发表回答