【发布时间】:2016-07-07 12:49:55
【问题描述】:
只有当数组中的元素等于我存储在会话中的当前月份时,我才想从集合中检索元素。例如,如果我的会话变量等于“juillet”,我希望只有在“moisrec”方法中具有“juillet”的项目:
Legumes = new Mongo.Collection("legumes");
if (Meteor.isServer) {
Meteor.startup(function() {
if (Legumes.find().count() === 0) {
var legumes = [{
nom: "poireau",
moisrec: ["juillet", "août"],
}, {
nom: "navet",
moisrec: ["octobre", "novembre"],
}, {
nom: "choux-fleur",
moisrec: ["juillet", "août"]
}];
// Insert sample data into db.
legumes.forEach(function(item) {
Legumes.insert(item);
});
}
});
}
我有一个看起来像这样的助手:
Template.Legumes.helpers({
legumes : function() {
return Legumes.find({});
}
});
我在模板之后使用 blaze:
{{#each legumes}}
<div class="col-sm-3">
<div class="thumbnail">
<img src="legumes/{{nom}}.jpg" alt="{{nom}}" width="400" height="300">
<p><strong>{{nom}}</strong></p>
<p>Période récolte : {{#each mois in moisrec}}<a>{{mois}} </a>{{/each}}</p>
<button class="btn" href="/legumes:{{_id}}">Fiche complète</button>
</div>
</div>
{{/each}}
谢谢
约安
【问题讨论】:
标签: javascript meteor meteor-blaze helpers