如何在ember JS中形成表时使用#if使用多个条件?

时间:2018-06-13 17:02:30

标签: ember.js

我正在使用Ember动态构建一个表

如何在形成表格时使用嵌套if

像这样的东西

{{#if ismorethanone && model.hasSize}}
                            <td> Hai  </td>
                            {{else}}
                                <td> Bye </td>
                        {{/if}}

我的代码

<script type="text/x-handlebars" data-template-name="index">
   <table class="table table-striped table-condensed">
    <thead>
        <tr>
            <th>Participant</th>
        </tr>
    </thead>
    <tbody id="ParticipantList">
        {{#each person in model}}
            <tr>
                <td> {{person.name}}</td>
                <td> {{person.city}}</td>
                {{#if ismorethanone}}
                     <td><img src="image.jpg" alt="Remove" {{action "removeUser" person.name}}></td>
                {{/if}}
            </tr>
        {{/each}}
    </tbody>
   </table>
</script>

http://jsfiddle.net/6Evrq/1937/

1 个答案:

答案 0 :(得分:1)

使用ember-truth-helpers

{{#if (and ismorethanone && model.hasSize)}}
  foo
{{else}}
  bar
{{/if}

或只是嵌套if s:

{{#if foo}}
  {{#if bar}}
    one
  {{else}}
    two
  {{/if}}
{{/if}}