Can';t将meteor服务器方法中的typeahead值返回给客户端

Can';t将meteor服务器方法中的typeahead值返回给客户端,meteor,typeahead.js,typeahead,Meteor,Typeahead.js,Typeahead,尝试在我的meteor应用程序的表单上实现Sergey-t的Typeahead包 问题是,我似乎无法将typeahead结果从服务器返回到客户端 如果我在客户端创建一个测试数组并通过助手返回它,那么Typeahead就可以工作 此外,所有查询结果都成功地记录在服务器控制台中。唯一的问题是我似乎无法把它们带回客户那里 我的JS客户端控制台没有显示任何错误,这似乎很奇怪 任何帮助都将不胜感激 HTML JS服务器端代码 Template.typeaheadTemplate.rendered = fu

尝试在我的meteor应用程序的表单上实现Sergey-t的Typeahead包

问题是,我似乎无法将typeahead结果从服务器返回到客户端

如果我在客户端创建一个测试数组并通过助手返回它,那么Typeahead就可以工作

此外,所有查询结果都成功地记录在服务器控制台中。唯一的问题是我似乎无法把它们带回客户那里

我的JS客户端控制台没有显示任何错误,这似乎很奇怪

任何帮助都将不胜感激

HTML

JS服务器端代码

Template.typeaheadTemplate.rendered = function() {
    Meteor.typeahead.inject();
};

Template.typeaheadTemplate.helpers({

    search: function(query, sync, callback) {
      // alert( "typeaheadTemplate.search() " ) ;
      // debugger;
      Meteor.call('search', query, {}, function(err, res) {
        if (err) {
          console.log(err);
          return err;
        }
        callback(res.map(function(v){ return {value: v.Name}; }));
      });
    }

  });
typeahead = new Mongo.Collection("typeahead");
typeahead._ensureIndex({"Name": "text"});         // index by Name

Meteor.methods({

    search: function(query, options) {
      // console.log("Search Result") ;
      // return "SEARCH RESULT" ;
    // debugger;
    // if (!query) return [];

    options = options || {};
    // guard against client-side Denial of Service: hard limit to 50
    if (options.limit) { options.limit = Math.min(50, Math.abs(options.limit)); }
    else { options.limit = 50; }

    var re = "^" + query + ".*$" ;
    var th = typeahead.find({ "Name" : {$regex : re } }, {fields: { Name : 1 }});
    console.log("query " + query + " -> " + th.count() );
    th.forEach(function (autoCompleteString) {
      console.log("> " + autoCompleteString.Name);
    });
    return th;
  }});
如果有帮助,以下是我正在使用的软件包:

accounts-password          1.1.4  Password support for accounts
accounts-ui                1.1.6  Simple templates to add login widgets to an app
anonyfox:scrape            0.0.10  Scrape any Website or RSS/Atom-Feed with ease
blaze-html-templates       1.0.1  Compile HTML templates into reactive UI with Meteor B...
check                      1.1.0  Check whether a value matches a pattern
ecmascript                 0.1.6* Compiler plugin that supports ES2015+ in all .js files
ejson                      1.0.7  Extended and Extensible JSON library
es5-shim                   4.1.14  Shims and polyfills to improve ECMAScript 5 support
fortawesome:fontawesome    4.5.0  Font Awesome (official): 500+ scalable vector icons, ...
froatsnook:request         2.67.0  A Simplified HTTP client which supports retrieving b...
http                       1.1.1  Make HTTP calls to remote servers
insecure                   1.0.4  (For prototyping only) Allow all database writes from...
jquery                     1.11.4  Manipulate the DOM using CSS selectors
less                       2.5.1  Leaner CSS language
meteorhacks:npm            1.5.0  Use npm modules with your Meteor App
mobile-experience          1.0.1  Packages for a great mobile user experience
mongo                      1.1.3  Adaptor for using MongoDB and Minimongo over DDP
mrt:cheerio                0.3.2  Simple Cheerio NPM wrapper
mrt:fittext                1.2.0  FitText packaged for Meteor.
mrt:jquery-easing          1.3.0  GSGD's jQuery easing plugin for Meteor
mrt:twit                   0.2.0  Twitter API Client
npm-container              1.2.0+ Contains all your npm dependencies
okgrow:promise             0.9.5  Utilities for Promise-based wrappers, method calls, h...
peppelg:bootstrap-3-modal  1.0.4  Simple usage of bootstrap 3 modals.
sacha:spin                 2.3.1  Simple spinner package for Meteor
sergeyt:typeahead          0.11.1_8  Autocomplete package for meteor powered by twitter...
session                    1.1.1  Session variable
standard-app-packages      1.0.6  Moved to meteor-platform
standard-minifiers         1.0.2  Standard minifiers used with Meteor apps by default.
stevezhu:fbgraph           2.0.0  Node.js module to access the Facebook graph api.
timmyg:wow                 1.0.1  WOW css animations
tracker                    1.0.9  Dependency tracker to allow reactive callbacks
twbs:bootstrap             3.3.6  The most popular front-end framework for developing r...
underscore                 1.0.4  Collection of small helpers: _.map, _.each, ...

不要通过方法返回数据,而是尝试订阅这些搜索结果。@FaysalAhmed感谢您的建议。我不明白这将如何解决这个问题。meteor typeahead的官方文档没有关于发布/订阅的建议,建议只对所有服务器端typeahead使用meteor.call。如果您仔细查看示例,您会发现一些
dbName.find()
在客户端,这基本上意味着已经订阅了一些数据。@FaysalAhmed我已经仔细检查了文档中是否提到订阅或发布。看看主页,这里没有提到Pub/Sub,该页面上唯一的服务器端示例是meteor.call。在文档页面上也没有提到任何订阅或发布:另外,我在服务器控制台中打印了查询结果,我只是无法将它们返回到客户端。除了Sergey-T的示例之外,internet上Meteor anywhere的大型、可工作的提前键入服务器端实现的示例几乎为零。与其通过方法返回数据,不如尝试订阅这些搜索结果。@FaysalAhmed感谢您的建议。我不明白这将如何解决这个问题。meteor typeahead的官方文档没有关于发布/订阅的建议,建议只对所有服务器端typeahead使用meteor.call。如果您仔细查看示例,您会发现一些
dbName.find()
在客户端,这基本上意味着已经订阅了一些数据。@FaysalAhmed我已经仔细检查了文档中是否提到订阅或发布。看看主页,这里没有提到Pub/Sub,该页面上唯一的服务器端示例是meteor.call。在文档页面上也没有提到任何订阅或发布:另外,我在服务器控制台中打印了查询结果,我只是无法将它们返回到客户端。除了Sergey-T的示例之外,还有几乎零个大型、可工作的Meteor anywhere服务器端实现示例。
accounts-password          1.1.4  Password support for accounts
accounts-ui                1.1.6  Simple templates to add login widgets to an app
anonyfox:scrape            0.0.10  Scrape any Website or RSS/Atom-Feed with ease
blaze-html-templates       1.0.1  Compile HTML templates into reactive UI with Meteor B...
check                      1.1.0  Check whether a value matches a pattern
ecmascript                 0.1.6* Compiler plugin that supports ES2015+ in all .js files
ejson                      1.0.7  Extended and Extensible JSON library
es5-shim                   4.1.14  Shims and polyfills to improve ECMAScript 5 support
fortawesome:fontawesome    4.5.0  Font Awesome (official): 500+ scalable vector icons, ...
froatsnook:request         2.67.0  A Simplified HTTP client which supports retrieving b...
http                       1.1.1  Make HTTP calls to remote servers
insecure                   1.0.4  (For prototyping only) Allow all database writes from...
jquery                     1.11.4  Manipulate the DOM using CSS selectors
less                       2.5.1  Leaner CSS language
meteorhacks:npm            1.5.0  Use npm modules with your Meteor App
mobile-experience          1.0.1  Packages for a great mobile user experience
mongo                      1.1.3  Adaptor for using MongoDB and Minimongo over DDP
mrt:cheerio                0.3.2  Simple Cheerio NPM wrapper
mrt:fittext                1.2.0  FitText packaged for Meteor.
mrt:jquery-easing          1.3.0  GSGD's jQuery easing plugin for Meteor
mrt:twit                   0.2.0  Twitter API Client
npm-container              1.2.0+ Contains all your npm dependencies
okgrow:promise             0.9.5  Utilities for Promise-based wrappers, method calls, h...
peppelg:bootstrap-3-modal  1.0.4  Simple usage of bootstrap 3 modals.
sacha:spin                 2.3.1  Simple spinner package for Meteor
sergeyt:typeahead          0.11.1_8  Autocomplete package for meteor powered by twitter...
session                    1.1.1  Session variable
standard-app-packages      1.0.6  Moved to meteor-platform
standard-minifiers         1.0.2  Standard minifiers used with Meteor apps by default.
stevezhu:fbgraph           2.0.0  Node.js module to access the Facebook graph api.
timmyg:wow                 1.0.1  WOW css animations
tracker                    1.0.9  Dependency tracker to allow reactive callbacks
twbs:bootstrap             3.3.6  The most popular front-end framework for developing r...
underscore                 1.0.4  Collection of small helpers: _.map, _.each, ...