【发布时间】:2015-04-15 12:37:37
【问题描述】:
(这是我在流星中的第一个应用) 我有问题,我无法从集合中获取数据。 我要做日历。 我有日期名称的集合,并有这个月天数的数组,而 mondey 是 0 等。 在集合中,我有名称和索引,如果索引等于数组中的天数,我想显示天的名称 我不知道我做得好不好。 请注意我所有的应用程序代码,它在文件夹中排序,但我只是在需要帮助的地方复制了代码
<template name="calendar">
{{#each months}}
<span>{{name}}</li>
{{/each}}
</ul>
{{days}}
<div class="calendar">
<ul>
{{#each daysofweek}}
<li>
{{index}}
</li>
{{/each}}
</ul>
{{#each generateCalendar}}
<ul>
<li>
<ul>
{{#each this}}
<li>
{{day}}: {{dayOfWeek}}
</li>
{{/each}}
</ul>
</li>
</ul>
{{/each}}
</div>
<!-- <button class="remove">click</button>-->
</template>
db = new Array;
db['dayoftheweek'] = new Mongo.Collection('dayoftheweek');
db['months'] = new Mongo.Collection('months');
Template.calendar.helpers({
'daysofweek': function () {
return db['dayoftheweek'].find();
},
'generateCalendar': function () {
var tab = [];
var daysInMonth = Session.get('currentMonthDays');
var fDay = Session.get('currentMonthFDay');
for (var i = 1; i <= daysInMonth; i++) {
tab[i] = {day: i, dayOfWeek: fDay};
if (fDay === 6) {
fDay = 0;
} else {
fDay++;
}
}
var weeks = [];
var i = 0;
while (tab.length > 0) {
if (i === 0) {
weeks[i] = tab.splice(0, (8 - Session.get('currentMonthFDay')));
i++;
} else {
weeks[i] = tab.splice(0, 7);
i++;
}
}
return weeks;
}
});
Meteor.methods({
'removeFromDb': function(selected, dbname){
db[dbname].remove(selected);
}
});
【问题讨论】:
标签: javascript mongodb meteor