javascript - Meteor checkbox - Display Value of expression as String, not interpreted as Boolean -
i have checkbox implemented , it's working 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 } }); } });
i want display value ("true" or "false") depending on checkbox's state. seems expression "{{ checked }}" evaluatiated true or false, , if true returns value of corresponding document entry. how can display content string ("true" / "false")?
thanks in advance! vin
you add helper transforms checked
bool string using tostring()
function:
checkedstring: function () { return this.checked.tostring(); }
and use helper in template:
<input type="checkbox" checked="{{checked}}" class="toggle-checked"> {{name}}: {{checkedstring}}
see meteor pad demo.
Comments
Post a Comment