A
A
Alecxandrys2016-05-02 15:24:30
JavaScript
Alecxandrys, 2016-05-02 15:24:30

Change template state variable from outside?

Good
afternoon According to the manual, using the if block in the Spacebars template in Meteor I go as follows:
HTML side:

<div class="left-panel">
        {{#if reconnaissance.state}}
            {{#each cards}}
                {{name}}
            {{/each}}
        {{/if}}
    </div>

js side:
Template.Battlefield.helpers({
    name1       : function()
        {
            return battles.findOne().name1;
        },
    name2       : function()
        {
            return battles.findOne().name2;
        },
    cards:function()
        {
            if (Meteor.user().username==battles.findOne().name1)
                {
                    return BS.deck1;
                }
            else if (Meteor.user().username==battles.findOne().name2)
            {
                return BS.deck2;
            }
            else {
                    alert ("You name doesn't consist in battlestate");
                }

        },
    reconnaissance:
        {
            state:true
        }
});

In a similar state, everything works, but there is a need to change the state from outside the template. How to change the state of a variable to remove the block?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Idel Gizatullin, 2016-05-02
@Alecxandrys

Template.Battlefield.helpers.reconnaissancecan be made into a function, for example:

Template.Battlefield.helpers({
    reconnaissance: function() {
        var randomBoolean = Math.random() < 0.5;
        return {
            state: randomBoolean
        }
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question