dimanche 30 août 2015

Meteor checkbox - Display Value of expression as String, not interpreted as Boolean

I have a checkbox implemented and it's working just fine.

HTML:

<form>
    <ul>
        {{#each checkbox}}
        <li>
            <input type="checkbox" checked="{{checked}}" class="toggle-checked"> {{name}}: {{checked}}
        </li>
        {{/each}}
    </ul>
</form>

JS:

Cbtest = new Mongo.Collection('cbtest');

Template.checkbox.helpers({
    checkbox: function () {
        return Cbtest.find();
    }
});

Template.checkbox.events({
    "click .toggle-checked": function () {
       var self = this;
        Meteor.call("setChecked", self._id, !self.checked);
    }
});

Meteor.methods({
    setChecked: function (checkboxId, setChecked) {
        CbTest.update(checkboxId, {
            $set: {
                checked: setChecked
            }
        });
    }
});

enter image description here

I want to display the Value ("true" or "false") depending on the checkbox's state. As now it seems that the Expression "{{ checked }}" is evaluatiated to true or false, and if its true then it returns the value of the corresponding document entry. How can i just display the content as String ("true" / "false")?

Thanks in advance! Vin




Aucun commentaire:

Enregistrer un commentaire