2016-05-03 7 views
0

私は自分のプロジェクトに検索機能を持っています。自動公開を使わずに結果を公開する必要があります。流星:自動公開を使わないで検索(フィルタ)を作成する

HTML

<template name="search"> 
    <form id="searchform"> 
    <input type="text" id="kategori" placeholder="Sila masukkan maklumat carian."/> 
    <button>Carian</button> 
    </form> 
    <hr/> 
    <h3>Maklumat</h3> 
    <ol> 
    {{#each profil}} 
     <li>{{jenama}}</li> 
    {{/each}} 
    </ol> 
</template> 

JS:

Template.search.events({ 
    "submit #searchform": function (e) { 
    e.preventDefault(); 
    Session.set("kategori", e.target.text.value); 
    } 
}); 

Template.search.helpers({ 
    profil: function() { 
    return Profil.find({ 
     kategori: Session.get('kategori'), 
    }); 
    } 
}); 

答えて

1

あなたは単にがフィルタリングパブリケーションにを購読することができます。

クライアント:

Template.search.events({ 
    "submit #searchform": function (e) { 
    e.preventDefault(); 
    Session.set("kategori", e.target.text.value); 
    Meteor.subscribe('profiles',Session.get('kategori')); 
    } 
}); 

サーバー:ドキュメントのセットは、あなたの出版物によって定義されることになるので

Template.search.helpers({ 
    profil: function() { 
     return Profil.find(); 
    } 
}); 

Meteor.publish('profiles',function(kategori){ 
    return Profil.find({ kategori: kategori }); 
}); 

あなたはまたにあなたのヘルパーを簡素化することができ、同じコレクションに、他のサブスクリプションを持っていない場合。

実際には、他の出版物からの文書が表示されないようにするために、通常、出版社での検索と同じ検索をヘルパーで使用します。

+0

お返事ありがとうございます。 Iron routerはどうですか?私はいくつかのデータ関数を入れておく必要があります。 – nurul

+0

必ずしも、パラメータを使用して経路を検索しない限り、必ずしもそうではありません。 –

関連する問題