0
我遇到問題,試圖在模板中使用名爲created
的收集字段。這是一個保留字,還是什麼?手把不能正確呈現收集字段
是陷入困境的看起來像這樣的模板的一部分:
{{#each threads}}
<tr>
<td><a href="forumShowThread?id={{_id}}">{{topic}}</a></td>
<td>{{creator.username}}</td>
<!-- The line below is the evil one. -->
<td>{{created}}</td>
<td>{{lastPost.poster.username}} {{datetime lastPost.posted}}</td>
</tr>
{{/each}}
在瀏覽器中我發現線程在我的控制檯如下:
[
Object
_id: "ngEtonq8XM36KtG3S"
created: 1375881336372
creator: function(){
creatorId: "ZmKpMdhP4GtzQo98e"
lastPost: function(){
posts: function(){
subCategory: function(){
subCategoryId: "axgd2xzctkfmphmwM"
topic: "Testing"
__proto__: Object
,
Object
_id: "XafEMvAvcRzpBKxG3"
created: 1375882602652
creator: function(){
creatorId: "ZmKpMdhP4GtzQo98e"
lastPost: function(){
posts: function(){
subCategory: function(){
subCategoryId: "axgd2xzctkfmphmwM"
topic: "Testnign again"
__proto__: Object
,
Object
_id: "CZmf5MfqZrB28SLPB"
created: 1375883440242
creator: function(){
creatorId: "ZmKpMdhP4GtzQo98e"
lastPost: function(){
posts: function(){
subCategory: function(){
subCategoryId: "axgd2xzctkfmphmwM"
topic: "And another shoot"
__proto__: Object
]
顯然3個線程,他們都有一個創建的領域。但是,瀏覽器顯示以下內容:
<tr>
<td><a href="forumShowThread?id=CZmf5MfqZrB28SLPB">And another shoot</a></td>
<td>Peppe L-G</td>
<td></td>
<td>Peppe L-G 7 August 2013 15:50</td>
</tr>
<tr>
<td><a href="forumShowThread?id=XafEMvAvcRzpBKxG3">Testnign again</a></td>
<td>Peppe L-G</td>
<td></td>
<td>Peppe L-G 7 August 2013 15:36</td>
</tr>
<tr>
<td><a href="forumShowThread?id=ngEtonq8XM36KtG3S">Testing</a></td>
<td>Peppe L-G</td>
<td></td>
<td>Peppe L-G 7 August 2013 15:35</td>
</tr>
爲什麼不created
場表現?
我試圖用<td>{{this.created}}</td>
代替<td>{{created}}</td>
,然後瀏覽器顯示如下:
<tr>
<td><a href="forumShowThread?id=CZmf5MfqZrB28SLPB">And another shoot</a></td>
<td>Peppe L-G</td>
<td>1375883440242</td>
<td>Peppe L-G 7 August 2013 15:50</td>
</tr>
<tr>
<td><a href="forumShowThread?id=XafEMvAvcRzpBKxG3">Testnign again</a></td>
<td>Peppe L-G</td>
<td></td>
<td>Peppe L-G 7 August 2013 15:36</td>
</tr>
<tr>
<td><a href="forumShowThread?id=ngEtonq8XM36KtG3S">Testing</a></td>
<td>Peppe L-G</td>
<td></td>
<td>Peppe L-G 7 August 2013 15:35</td>
</tr>
的created
場現在工作的第一線,而不是休息。這是怎麼回事?!
如果它是相關的,這裏的整個模板:
<template name="pageForumSubCategory">
<div class="layoutContentForumSubCategory">
{{#with subCategory}}
<h1>
<a href="forum">Forum</a>
→
{{name}}
{{#if currentUser}}
→
<a href="forumCreateNewThread?id={{_id}}">New thread</a>
{{/if}}
</h1>
{{#if threads.count}}
<table border="2">
<thead>
<tr>
<th>Topic</th>
<th>Creator</th>
<th>Created</th>
<th>Last post</th>
</tr>
</thead>
<tbody>
{{#each threads}}
<tr>
<td><a href="forumShowThread?id={{_id}}">{{topic}}</a></td>
<td>{{creator.username}}</td>
<!-- The line below is the eveil one. -->
<td>{{this.created}}</td>
<td>{{lastPost.poster.username}} {{datetime lastPost.posted}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
<p>Well, it's more or less empty here (so far).</p>
{{/if}}
{{else}}
<h1>
<a href="forum">Forum</a>
→
???
</h1>
<p>Hmm... There is no subforum with the given id. Strange, but there's nothing I can do about it. Sorry.</p>
{{/with}}
</div>
</template>
嗯......當我使用'#each'時,是不是切換了上下文,所以'created'文件會遮蓋'created'模板?或者,顯然不是(我測試過,你是對的)。但是現在我明白爲什麼集合'Meteor.users'有一個名爲'createdAt'的字段,我發現它有點奇怪^^ –