Reputation: 427
I am building a meteor based webapp. One of the pages has a drop down menu, which the user has to select options (various school districts) from. The selection needs to be detected, followed by querying the database filtering documents based on the selection and counting the documents returned, followed by rendering a template (a chart built using highcharts.js)
Code as follows:
Template.districtDropdown.events({
'change' : function(event, template){
event.preventDefault();
var selectedValue = template.$("#selectDistrict").val();
console.log("You Selected " + selectedValue);
var filter = {
find: {
'School District' : selectedValue
}
};
Meteor.subscribe('aggByDistrict', filter);
productNames2 = _.uniq(CombinedData.find().map( function(doc) { return doc.Product; }));
console.log(productNames2);
var productValues2 = [];
for(var i = 0; i < productNames2.length; i++) {
productValues2.push(CombinedData.find({'Product' : productNames2[i]}).count())
};
console.log(productValues2);
}
});
I'm facing three issues.
Can anyone give me ideas on how I can go about resolving these issues?
Upvotes: 1
Views: 108
Reputation: 9935
Several problems with your code
Subscribe
needs to be put in Template.districtDropdown.created
. If you subscribe during the events, there might be the postpone during the subscription and no data available during the eventsDOM
component. As in change #selectDistrict
and then, you select the value like this var selectedValue = $(event.target).val();
Upvotes: 1