2016-05-06 146 views
1

我正在写一个流星应用程序,并试图将自动完成功能添加到搜索框。数据非常大并且位于服务器上,所以我无法在客户端上完成所有操作。它基本上是一个用户数据库。如果我没有错,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 

我真的不明白的问题。当我查看包代码时,它看起来像是测试订阅字段是字符串而不是变量,它是。任何想法可能是什么问题?否则,有没有我可以从某个地方去做的最低工作范例?我在文档中找不到一个。

回答

1
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

希望这会有所帮助!