Hi,
On my app users can select things they want to do = “todos”. those things are saved on a global array on the client.js (it updates to and from mongoDB, so this is the main place i want to store the things the users wants to do).
the list of options the user can choose from is stable on the screen (static on the HTML), but i do want an indicator that an option (a “todo”) is selected, such as change of color.
i created this helper, but obviously im missing something:
each option in HTML (the 1 is for the click event to add the id name to the todos array):
<div class="col-sm-6 col-md-4 1" id='food'>
<div class="thumbnail">
<img src="#" alt="...">
<p>food</p>
</div>
</div>
the array that collects the todos (its never empty, because its constantly updated from mongo):
user_todos = [];
the helper: (basically it goes over the array, “finds” the objects with an id matching the item, AND NOW IM STUCK ON UPDATING THE CLASS NAME
Template.todos.helpers({
selcted: function() {
for (var i = 0; i < user_todos.length; i++) {
var object = document.getElementById(user_todos[i]);
object.className = 'yello_box'
}
}
});
please note that if i use this logic (get an element by id and change the class) as an on click event it works. im just not sure how to use the helper that iterates over an array corectly.
any ideas?
thanks!