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 つのスレッドがあり、それらにはすべて created フィールドがあります。しかし、ブラウザには次のように表示されます。
<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>