0

同様の質問を見たことがありますが、私の場合には適用できませんでした...

ルート定義を取得しましたiron-router

this.route('home', {
  path: '/',
  template: 'home',
  waitOn: function(){
    return [Meteor.subscribe('books'),Meteor.subscribe('authors'))];
  },
onBeforeAction: function(){
  Session.set('search_keywords', this.params.search);
  }
});

私のファイルでは、次のようhome.jsに表示するヘルパーを取得しました。books

Template.booksList.helpers({
  books: function () {
    if(Session.get("search_keywords")){
      keywords = new RegExp(Session.get("search_keywords"), "i");
      var result = Books.find({$or:[{name:keywords},{description:keywords},{tags:keywords}]},{sort: {updatedAt: 1}});
      if(result.count()===0){
         console.log('no results found')
         return [];
      }else{
        return result;
      }
    }
   }
 });

そして上home.html

<template name="booksList">
 <div class="row">
  {{#each books}}  
    {{> bookDetail}}
  {{/each}}
 </div>
</template>

http://mydomain.com/?search=Happy%20Potter目的は、すべてのハリー・ポッターの本を見つけるような URL からビューにアクセスすることです。

私が理解していない何か...ページが2回レンダリングされ、最初に結果がないことを示し、次に結果を表示します。理由がわかりますか?

ありがとう !

4

1 に答える 1

0

iron-router のドキュメントを見てください。特に、WaitOn フックに関するこのセクションでは、loadingTemplate の使用について説明しています。

参照: https://github.com/EventedMind/iron-router/blob/dev/DOCS.md#waiting-on-subscriptions-waiton

ルートのテンプレートを設定する方法と同様に、loadingTemplate を設定できます。例えば、

this.route('home', { path: '/', template: 'home', loadingTemplate: 'loading', ...

データの準備が整うまで loadingTemplate が表示され、サブスクリプションからのデータがメインの「ホーム」テンプレートにレンダリングされます。

それが役立つことを願っています。

于 2014-07-08T03:56:06.590 に答える