RZK*_*ZKY 1 meteor iron-router
有人可以解释为什么我得到ObjectID的全部值而不是干净的ID?
这就是我得到的:

和HTML输出:
<a href="/summary/ObjectID(%2254ab87a24c38814aa128da7b%22)">My Post</a>
Run Code Online (Sandbox Code Playgroud)
我没有做过任何与众不同的事情.现在非常基本的东西.刚试试Meteor第一次.
路由:lib/router.js
// Dashboard
Router.route('/dashboard', {name: 'dashboard'});
// Post detail
Router.route('/summary/:_id', {
name: 'postSummary',
data: function() {
return Post.findOne(this.params._id);
}
});
Run Code Online (Sandbox Code Playgroud)
列表页面模板:templates/posts/post_dashboard.html
{{#each posts}}
<tr>
<td>
<p><a href="{{pathFor 'postSummary'}}">{{title}}</a></p>
<p><small>Created at {{createdAt}}</small></p>
</td>
...
</tr>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
详细页面模板:templates/posts/post_summary.html
<template name="postSummary">
{{> postHeader}}
<h3>{{title}}</h3>
</template>
Run Code Online (Sandbox Code Playgroud)
模板助手:templates/posts/posts.js
Template.dashboard.helpers({
posts: function () {
return Post.find({});
}
});
Run Code Online (Sandbox Code Playgroud)
这是我安装的软件包,以防万一.
meteor-platform
autopublish
insecure
matthew:foundation5-sass
iron:router
jquery
useraccounts:core
useraccounts:foundation
accounts-password
accounts-facebook
accounts-google
accounts-ui-unstyled
aldeed:autoform
aldeed:collection2
forwarder:autoform-wizard
fortawesome:fontawesome
Run Code Online (Sandbox Code Playgroud)
Posts从控制台查询集合时,_id返回的文档中是字符串文字还是ObjectId对象?
假设它是后者,那就是为什么会发生这种情况,如果是这样,那可能是因为你已经insert在Mongo shell中使用了填充集合(或者从现有的MongoDB中恢复).默认情况下,Meteor插入在未指定id时使用字符串作为自动添加的id,而Mongo使用ObjectIds.
希望有所帮助,但如果我完全走错了轨道,请告诉我!
| 归档时间: |
|
| 查看次数: |
986 次 |
| 最近记录: |