流星自动完成服务器端

meteor autocomplete server-side

我正在编写一个 meteor 应用程序,我正在尝试向搜索框添加自动完成功能。数据很大,在服务器上,我不能全部放在客户端。它基本上是一个用户数据库。如果我没记错的话,mizzao:autocomplete 包应该可以做到这一点,但我似乎无法让它工作。

这是我在服务器上的内容:

Meteor.publish('autocompleteViewers', function(selector, options) {
  Autocomplete.publishCursor(viewers.find(selector, options), this);
  this.ready();
});

下面是我在客户端上用于搜索框的设置:

  getSettings: function() {
    return {
      position: 'bottom',
      limit: 5,
      rules: [{
        subscription: 'autocompleteViewers',
        field: '_id',
        matchAll: false,
        options: '',
        template: Template.vLegend
      }],
    };
  }

但我一直在客户端收到此错误:

Error: Collection name must be specified as string for server-side search at validateRule

我不太明白这个问题。当我查看包代码时,它似乎在测试订阅字段是否为字符串而不是变量,事实确实如此。知道问题可能是什么吗?否则我可以从某个地方找到一个最低限度的工作示例吗?我在文档中找不到。

Error: Collection name must be specified as string for server-side search at validateRule

您收到此错误是因为您没有在引号中指定 Collection 名称。

getSettings: function() {
 return {
   position: 'bottom',
   limit: 5,
   rules: [{
     subscription: 'autocompleteViewers',
     field: '_id',
     matchAll: false,
     collection: 'viewers', // <- specify your collection, in your case it is a "viewers" collection.
     options: '',
     template: Template.vLegend
   }],
 };

}

更多信息请阅读here

希望对您有所帮助!