【发布时间】:2013-12-11 14:01:26
【问题描述】:
我是第一次使用 Meteorjs 和 MongoDB。我正在开发一个问答应用程序。我有一个使用 Meteor 数据库调用获得的对象列表。我想遍历列表并希望将其属性之一拆分为长度 50,然后想将这些拆分对象的列表发送到数据库。我所拥有的是这个
Template.questions.questions = function () {
questions= Meteor.questions.find({topic_id: Session.get("currentTopicId")});
return questions
}
问题列表中的每个问题对象都有一个属性 question_text。使用循环我想将此属性拆分为 50 的长度,然后想将其推送到一个空列表并返回该列表。喜欢
questions_list=[]
for(i=0;i<questions.length;i++){
question=questions[i].question_text[0:50] // python syntex to get first 50 char of a string
questions_list.push(question
}
return questions_list
我的 HTML 就像
<tbody>
{{#each questions}}
<tr>
<td class="span2" style="overflow:hidden;width:50px">
<a href="#" data-id="{{_id}}" class="edit"> {{question_text}}</a>
</td>
</tr>
{{/each}}
</tbody>
建议我如何在meteorjs 中实现这一点。我的问题是,当我尝试遍历此问题列表时,有许多属性,例如集合、结果、查询。在这里我无法迭代这个对象列表。
我怎样才能得到meteorjs抛出的错误信息
【问题讨论】:
标签: mongodb meteor handlebars.js meteorite