Vitor Brito
Vitor Brito

Reputation: 29

Blaze spacebars

I'm having problem with if structure in blaze.

I've some recorders in my db called chamadas, some of these has value E and others null. When I try to iterate, it ever enter in the first if.

I want to separate the recorders by the status.

{{#each chamada in chamadas}}       
  {{#if chamada.status = 'E' }}
    <tr class="success">
        <td>{{chamada.senha}}</td>
        <td>{{chamada.tempo}}</td>
        <td>{{chamada.data_inicio}}</td>
        <td></td>
        <th><button id="{{chamada._id}}" value="{{chamada.senha}}" class="btn btn-block">Chamar</button></th>
        <td>{{chamada.status}}</td>
    </tr>
    {{else}} 
    {{#if chamada.status = 'A'}}
        <tr class="danger">
            <td>{{chamada.senha}}</td>
            <td>{{chamada.tempo}}</td>
            <td>{{chamada.data_inicio}}</td>
            <td></td>
            <th><button id="{{chamada._id}}" value="{{chamada.senha}}" class="btn btn-block">Chamar</button></th>
             <td>{{chamada.status}}</td>
         </tr>
    {{else}}
        {{#if chamada.status = 'F'}}
            <tr class="info">
                <td>{{chamada.senha}}</td>
                <td>{{chamada.tempo}}</td>
                <td>{{chamada.data_inicio}}</td>
                <td>{{chamada.data_fim}}</td>
                <td>{{chamada.status}}</td>
            </tr>
        {{/if}}
     {{/if}}
  {{/if}}
{{/each}}

Upvotes: 0

Views: 60

Answers (1)

zim
zim

Reputation: 2386

spacebars isn't that sophisticated. you can write helpers and pass in arguments. e.g.

{{#if statusE chamada.status }}

here's the helper:

Template.Foo.helpers({
    statusE = function(status) {
        return (status == 'E');
    }
});

one nice side-effect is that you can give your helpers descriptive names. i don't know what a status of 'E' is, but with a good helper name, you can communicate that to the dev who maintains the sometime code.

Upvotes: 2

Related Questions