I need to read values from a MongoDB Collection and then check the checkboxes in a Template based on a field in the Document which matches the value of a checkbox.
I populate the Template with the checkboxes like so:
<div id="seljoblocs" name="seljoblocs">
{{#each jobLocs}}
<input type="checkbox" value={{jl_jobloc}}><label>{{jl_jobloc}}</label>
{{/each}}
</div>
Here is the Template’s “jobLocs” Helper:
jobLocs: function() {
return JobLocations.find({}, {
sort: {
jl_jobloc: 1
},
fields: {
jl_jobloc: 1
}
});
}
When I display the Template and make a selection from an input select element:
Template.matchWorkersWithJobLocs.events({
'change #selworker': function(event, template) {
var workerid = template.find('#selworker').value;
// TODO: Add code to query Collection and then check the appropriate checkboxes
},
…I need to query that collection something like this:
Meteor.publish("workersJobLocsLookupByWorker", function (workerid) {
return WorkersJobLocsLookup.find( {wjllu_workerid: workerid}, {fields: {wjllu_jobloc}});
});
…so that it only returns the appropriate joblocs for a particular worker.
Then, with those returned Document field values, I want to check the appropriate checkboxes (where wjllu_jobloc == the checkboxes’ value).
How can I do that, especially seeing that, since the checkboxes are dynamically added (one checkbox for each Document in the WorkersJobLocsLookup Collection), they do not have id or name vals?