我有以下代码来尝试填充选择:
\ lib \ mongo.js:
JobLocations = new Mongo.Collection("jobLocations");
在\ server \ scheduler.js中:
Meteor.startup(function () {
// code to run on server at startup
if (JobLocations.find().count() == 0) {
console.log('JobLocations collection empty; inserting');
JobLocations.insert({ value: "1", display: "Uno" });
JobLocations.insert({ value: "2", display: "Dos" });
JobLocations.insert({ value: "3", display: "Tres" });
JobLocations.insert({ value: "4", display: "Cuatro" });
JobLocations.insert({ value: "5", display: "Cinco" });
JobLocations.insert({ value: "6", display: "Seis" });
JobLocations.insert({ value: "7", display: "Siete" });
JobLocations.insert({ value: "8", display: "Ocho" });
JobLocations.insert({ value: "9", display: "Nueve" });
JobLocations.insert({ value: "10", display: "Zehn" });
}
});
Meteor.publish("jobLocations", function () {
return JobLocations.find();
});
Meteor.methods({
'insertJobLocations': function(companyId, jobLoc) {
JobLocations.insert({
jl_companyid: companyId,
jl_jobloc: jobLoc,
jl_created_by: Meteor.userId()
});
}
});
\ client \ main.js:
Meteor.subscribe("jobLocations");
Template.tblScheduler.helpers({
jobLocations: function() {
return JobLocations.find();
}
});
\ client \ main.html:
<select name="date1Shift1JobLoc1Count" id="date1Shift1JobLoc1Count">
{{#each jobLocations}}
<option value={{jl_jobloc}}>{{jl_jobloc}}</option>
{{/each}}
</select>
我错过了什么或做错了什么?
从Collection中删除所有记录后,我将server.js中的服务器启动功能更改为:
Meteor.startup(function () {
// code to run on server at startup
if (JobLocations.find().count() == 0) {
console.log('JobLocations collection empty; inserting');
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Uno" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Dos" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Tres" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Cuatro" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Cinco" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Seis" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Siete" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Ocho" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Nueve" });
JobLocations.insert({ jl_companyid: "axx", jl_jobloc: "Zehn" });
}
});
......它仍然不起作用。
答案 0 :(得分:1)
尝试
jobLocations: function() {
return JobLocations.find().fetch();
}