javascript - Return different subset of data when clicking checkbox in Meteor -
i trying make simple-todo app given on meteor website.
here's code or view complete app on meteorpad:
<body> <div class="container"> <header> <h1>todo list</h1> <label class="hide-completed"> <input type="checkbox" checked="{{hidecompleted}}" /> hide completed tasks </label> <form class="new-task"> <input type="text" name="text" placeholder="type add new tasks" /> </form> </header> <ul> {{#each tasks}} {{> task}} {{/each}} </ul> </div> </body>
template.body.helpers({ tasks: function() { if (session.get("hidecompleted")) { // if hide completed checked, filter tasks return tasks.find({ checked: { $ne: true } }, { sort: { createdat: -1 } }); } else { // otherwise, return of tasks return tasks.find({}, { sort: { createdat: -1 } }); } }, hidecompleted: function() { return session.get("hidecompleted"); } });
the hidecompleted
checkbox not ommiting checked items list , after hours of braking head on it, still can't find bug. can please me out here?
you should use session.equals(key, value)
test if session variable equal value.
in case be:
template.body.helpers({ tasks: function(){ return session.equals("hidecompleted", true) ? tasks.find({checked: {$ne: true}}, {sort: {createdat: -1}}) : tasks.find({}, {sort: {createdat: -1}}); } });
furthermore, need register click event invert corresponding session value:
template.body.events({ "click #hide-tasks": function(e) { e.preventdefault(); session.set("hidecompleted", !session.get("hidecompleted")); } });
<input id="hide-tasks" type="checkbox" checked="{{hidecompleted}}" />
here's updated meteorpad.
Comments
Post a Comment