meteor search-sourceのthisチュートリアルに続き、私の現在のニーズに合うようにこの例を修正しました。 これは私が私のクライアント側のコントローラのコードを次しているMeteor検索ソースパッケージを使用しようとすると、エラーが発生するのはなぜですか?
Guides = new Mongo.Collection("guides");
私のlibディレクトリにあります。私のcollections.js
です。何らかの理由で
var options = {
keepHistory: 1000 * 60 * 5,
localSearch: true
};
var fields = ['title'];
GuideSearch = new SearchSource('guides', fields, options);
Template.guide_list.helpers({
getGuides: function() {
return GuideSearch.getData({
transform: function (matchText, regExp) {
return matchText.replace(regExp, "<b>$&</b>")
}
});
},
isLoading: function() {
return GuideSearch.getStatus().loading;
}
});
Template.guide_list.events({
"keyup #title": _.throttle(function(e) {
var text = $(e.target).val().trim();
GuideSearch.search(text);
}, 200)
});
私のサーバー側のコードとして
そしてこの
SearchSource.defineSource('guides', function(searchText, options) {
if(searchText) {
var regExp = buildRegExp(searchText);
var selector = {title: regExp}
return Guides.find(selector, options).fetch();
} else {
return Guides.find({}, options).fetch();
}
});
function buildRegExp(searchText) {
// this is a dumb implementation
var parts = searchText.trim().split(/[ \-\:]+/);
return new RegExp("(" + parts.join('|') + ")", "ig");
}
Exception in delivering result of invoking 'search.source': Meteor.makeErrorType/[email protected]://10.0.3.162:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:525:15
[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:4625:23
Connection/[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:3365:7
._launchConnection/self.socket.onmessage/<@http://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:2734:11
[email protected]://10.0.3.162:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:149:7
._launchConnection/[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:2733:9
[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:173:9
[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:1158:5
[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:1216:13
SockJS.websocket/[email protected]://10.0.3.162:3000/packages/ddp-client.js?250b63e6c919c5383a0511ee4efbf42bb70a650f:1363:9
私の入力フィールドに何かを入力するとき、私は次のエラーメッセージが表示されるこれは私のテンプレートコードです:
template(name="guide_list")
.format-properly
.container-fluid
.input-group#adv-search
.form-horizontal(role="form" method="POST" action="#")
.col-md-6
.form-group
label(for="contain") Guide title
input.form-control(type="text" id="title")
.col-md-6
.form-group
label(for="contain") Author
input.form-control(type="text" name="author")
.col-md-6
.form-group
label(for="hero") Select a hero
select.form-control(name="hero")
option(value="all" selected) All Heroes
option(value="Druid") Druid
option(value="Hunter") Hunter
option(value="Mage") Mage
option(value="Paladin") Paladin
option(value="Priest") Priest
option(value="Rogue") Rogue
option(value="Shaman") Shaman
option(value="Warlock") Warlock
option(value="Warrior") Warrior
.col-md-6
.form-group
label(for="filter") Filter by
select.form-control(name="filterBy")
option(value="0" selected) All guides
option(value="most_viewed") Most viewed
option(value="top_rated") Top rated
option(value="most_commented") Most commented
.container-fluid
.table-responsive
table.table.table-hover
thead
tr
th hero
th title
th author
th updated
th dust
th
span.glyphicon.glyphicon-eye-open
th
span.glyphicon.glyphicon-heart
th
span.glyphicon.glyphicon-comment
tbody
each guides
tr
td {{hero}}
td
a(href="/guide/{{formatId _id}}") {{title}}
td {{authorUsername}}
td {{moFormat modifiedAt 'YYYY-MM-DD'}}
td {{dust}}
td {{hitCount}}
td {{rating}}
td {{commentCount}}
tbody
each getGuides
tr
td {{hero}}
td
a(href="/guide/{{formatId _id}}") {{title}}
td {{authorUsername}}
td {{moFormat modifiedAt 'YYYY-MM-DD'}}
td {{dust}}
td {{hitCount}}
td {{rating}}
td {{commentCount}}
何か助けや提案をいただければ幸いです。
編集:私は問題がGuideSearch.search
メソッドに渡されたoptions
の不足であることを信じ1.4.2
'ガイドは=新しいMongo.Collection(「ガイド」);'で定義されていますクライアントサイドスクリプト。 'Guides'もサーバーサイドスクリプトで呼び出されていますが、クライアントスクリプトで定義されているため利用できません。そのコード行を 'lib'フォルダ内のjsファイルに移動してください。そうすれば、サーバとクライアントの両方で利用できるようになります。そうでない場合は、テンプレートからHTMLを含めることができます。 –
@BrianShamblenコレクションの宣言は誤りではありませんでした。しかし、私は自分の投稿を編集してテンプレートを投稿しました:) –
これは私が私の答えで言及した(文書化されていない)問題によるものだと思います。そうでない場合は、サーバーログにエラーがないかどうかを確認します。このパッケージは少しの愛と更新が必要です:) – MasterAM