【发布时间】:2016-07-21 02:35:43
【问题描述】:
我正在尝试从名为“Babysitters”的架构/集合中显示保姆的独特个人资料(即:保姆用户名、城市、邮政编码等...)。
网址正确包含保姆唯一_id,例如:
但我无法检索所有其他字段。
我尝试在两个文件中查询 MongoDB:routes.js 和模板 test.js
1) 在 routes.js 中
Router.route('/test/:_id', {
name: 'test',
data: function () {
return Babysitters.findOne({ _id: this.params._id });
}
});
2) 在 test.js 中
Template.test.helpers({
data: function () {
//sitterusername = this.params.sitterusername;
//console.log(this.params._id );
return Babysitters.findOne( { _id: this.params._id });
}
});
html 文件:test.html
<template name="test">
{{#with data}}
<ul>
<li><img src="/" {{photourl}} height="100" width="100" ></li>
<li>Babysitter username: {{ sitterusername }}</li>
<li>Presentation: {{ presentation }}</li>
<li>City: {{ city }}</li>
<li>Postal Code: {{ postalcode }}</li>
<li>Mother tongue: {{ mothertongue }}</li>
<li>Languages spoken {{ languagesspoken }}</li>
<li>Experience {{ experience }}</li>
<li>Homework help: {{ homeworkhelpavailable }}</li>
<li>Hourly wages: {{ hourlywages }} €/h</li>
</ul>
{{/with}}
</template>
我尝试了各种方法,但集合字段从未出现在 HTML 文件中。
感谢您的帮助,这里是新手。
K.
【问题讨论】:
-
你用的是哪个路由器?
-
如果你写 'console.log(Babysitters.findOne( { _id: this.params._id }));' 会发生什么应用程序运行时在浏览器控制台中?
-
1) 路由器是铁路由器
-
2) 当我运行 console.log(Babysitters.findOne( { _id: this.params._id }));在控制台中,我得到: Uncaught TypeError: Cannot read property '_id' of undefined
-
您必须在路由器中的断点处才能定义
this.params._id。该命令在控制台中的任何状态下都不起作用。
标签: meteor meteorite meteor-autoform meteor-helper