Cómo implementar no con la instrucción if en Ember Manillar?


Tengo una declaración como esta:

{{#if IsValid}}

Quiero saber cómo puedo usar la declaración if con not like that:

{{#if not IsValid}}
Author: Daniel Kmak, 2012-05-10

6 answers

Respuestas simples para preguntas simples:

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

También tenga en cuenta que puede insertar un {{else}} entre un {{#if}} o {{#unless}} y la etiqueta de cierre.

 342
Author: Christopher Swasey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-13 14:00:46

Tienes muchas maneras de hacer eso.

1. Use {{unless}}:

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

2. Utilice el ayudante inline-if:

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

3. Use ember-truth-helpers addon:

{{#if (not isValid)}}
  ...
{{else}}
  ...
{{/if}}
 15
Author: Daniel Kmak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-26 12:59:18

unless ayudante de bloque (ayudante incorporado)

unless helper es el inverso del helper if.

Su bloque será renderizado si la expresión devuelve un valor falsy.

  {{#unless valid}}
  <h3 class="warning">WARNING</h3>
  {{/unless}}
 2
Author: Xinyang Li,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-20 06:30:29
{{#if items.length}}
    //Render
{{/if}}

Aquí los artículos.longitud .. si devuelve algún valor excepto null, entonces solo entrará en el bucle if.

NOTA : También puede comprobar los valores booleanos. En el bloque If

{{#if booleanFloag}}
 1
Author: Venkat Thotakura,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-24 07:17:17

Se puede hacer de múltiples maneras.

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}}
 1
Author: Nitin9791,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-31 11:42:43

Las instrucciones a continuación ayudarán a full si desea usar if y else:

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

NOTA : No cierre el bloque if hasta que logic termine ...

 0
Author: Venkat Thotakura,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-20 06:44:58