无法将流量服务器方法的预先输入值返回给客户端

时间:2016-02-08 00:05:44

标签: meteor typeahead.js typeahead

尝试在我的流星应用中的表单上实现Sergey-t的Typeahead包。

问题是,我似乎无法将服务器的预先输出结果返回给客户端。

如果我在客户端创建测试数组并通过帮助程序返回,则Typeahead有效。

此外,所有查询结果都在服务器控制台中成功记录。唯一的问题是我似乎无法让他们回到客户端。

我的JS客户端控制台没有显示任何错误,这看起来很奇怪。

非常感谢任何帮助。

HTML

<template name="typeaheadTemplate">

<!-- <input id="entry-field" class="typeahead input-lg form-control" type="text" name="text" placeholder="Paste or Enter your ID" autocomplete="off" spellcheck="off" data-source="search"/> -->

<input class="form-control typeahead" name="textEntry" type="text"
placeholder="Paste or Enter your ID ..."
autocomplete="off" spellcheck="off"
data-source="search"/>

</template>

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}; }));
      });
    }

  });

JS服务器端代码

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, ...

0 个答案:

没有答案