【发布时间】:2015-02-10 01:07:28
【问题描述】:
我在 Meteor 中向客户端显示数据库中的项目时遇到了困难。在模板 user_places 中,我想显示集合中文档的内容,并根据文档的创建对每个位置进行排序。
但是,尽管代码编译并运行,但我看不到 {{>user_places{{ 所在的位置。
我怀疑我输入了错误的查询:
return Places_Collection.find({ownerId: Meteor.userId()}, {sort: {添加时间:-1}});
无论如何,这是我的代码。注意 Meteor.userId() 确实包含一个值,所以让我们假设有一个用户登录。
html:
<head>
<title>Test</title>
<head>
<body>
{{ul}}
{{#each places}}
{{>user_places}}
{{/each}}
{{/ul}}
...
</body>
<template name="user_places">
<li>You have been to {{place_id}} from {{start}} to {{end}}</li>
</template>
javascript:
...
//client code
Meteor.subscribe('places_collection');
Template.user_places.helpers({
places: function() {
return Places_Collection.find({ownerId: Meteor.userId()}, {sort: {addedAt: -1}});
}
)};
...
Places_Collection (Mongodb) 中的示例文档
{
added_At: ISODate("2015-0207TIF:39:48:837Z"),
ownerId: "~userToken~",
start: "2014-02-02",
end: "2014-04-03:,
place_id "Canada"
_id: "~documentToken~"
}
如果您需要更多代码,请随时提出。
【问题讨论】: