为什么我的 select 没有填充此 Meteor 代码?
Why is my select not being populated with this Meteor code?
我有以下代码来尝试填充 select:
在\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>
我错过了什么或做错了什么?
更新
从集合中删除所有记录后,我将 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" });
}
});
...还是不行。
尝试
jobLocations: function() {
return JobLocations.find().fetch();
}
我有以下代码来尝试填充 select:
在\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>
我错过了什么或做错了什么?
更新
从集合中删除所有记录后,我将 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" });
}
});
...还是不行。
尝试
jobLocations: function() {
return JobLocations.find().fetch();
}