0

「もっと見る」というリンクをクリックして、アイテムの #each ループから単一のレコードを開こうとしています。リンクをクリックすると、単一の記事に移動します。Flow ルーターをセットアップして動作させましたが、入ってくるはずのデータが見えません。

単一の記事のテンプレート ヘルパーは次のようになります

Template.collectionSingle.helpers({
    articles: function () {
      var id = FlowRouter.getParam('_id')
      return theCollection.findOne({_id: id});
    }
  });

}

私のルートは次のようになります

FlowRouter.route('/collection/:_id', {
    name: 'collection',
    action() {
        BlazeLayout.render("AppLayout", {main: "collectionSingle"});
    }
});

テンプレート「collectionSingle」は次のようになります

<template name="collectionSingle">
<h1>{{title}}</h1>
<h1>This is a test</h1>
  <img src="{{thumbnail}}" alt="" />
</template>

http://localhost:3000/collection/thePublication-0に移動する と、「これはテストです」というテスト メッセージだけが表示されますが、{{title}} もサムネイルも表示されません。

さらに、私が変更すると:

return theCollection.findOne({_id: id});

私のコレクションの別の 1 つに:

return OtherCollection.findOne({_id: id});

http://localhost:3000/collection/thePublication-0 

同じまま。

記事ごとに 1 つの記事ページを作成し、それらをフロー ルーターに適切にリンクするにはどうすればよいですか?

4

1 に答える 1

1

データ コンテキストを返すテンプレート ヘルパーを実際に使用する必要があります。

<template name="collectionSingle">
<h1>{{title}}</h1>
<h1>This is a test</h1>
{{#with articles}}
  <img src="{{thumbnail}}" alt="" />
{{/with}}
</template>

articlesヘルパーは 1 つのドキュメントを返すため、{{#with articles}}. カーソルまたは配列が返された場合は、 でループします{{#each articles}}。通常の慣習では、前者には単数形を使用し、後者には複数形を使用します。

于 2016-06-10T01:05:44.523 に答える