我尝试在我的应用中执行下拉列表。首先我使用流星,这样的特定应用程序ofc :) 第二件事是我使用sebdah / meteor-autocompletion包,因为我希望我的结果以特定的方式排序和限制。
我需要的最后一件事就是将结果分组。 例如:如果我有两个名为" blah"我想只得到1" blag"在我的下拉列表"自动完成"列表。
一些代码:
HTML:
<template name="InvoicesEditInsertInsertForm">
<input id="descriptionautocomplete" type="text" name="description" value="" class="form-control" autofocus="autofocus" placeholder="New Item...">
</template>
JS:
Template.InvoicesEditInsertInsertForm.rendered = function() {
AutoCompletion.init("input#descriptionautocomplete");
};
Template.InvoicesEditInsertInsertForm.events({
'keyup input#descriptionautocomplete': function () {
AutoCompletion.autocomplete({
element: 'input#descriptionautocomplete', // DOM identifier for the element
collection: InvoicesItem, // MeteorJS collection object
field: 'description', // Document field name to search for
limit: 5, // Max number of elements to show
sort: { modifiedAt: -1 },
}); // Sort object to filter results with
},
});
我需要使用可以对我的&#34;描述&#34;进行分组的功能。这里。
我试图在帮手中做到这一点,我在屏幕上看到它,但说实话,我不知道如何把它放到我的下拉菜单中:(
try: function() {
var item= InvoicesItem.find({},{sort:{modifiedAt:-1}}).fetch();
var descriptions={};
_.each(item,function(row){
var description = row.description;
if(descriptions[description]==null)
descriptions[description]={description:description};
});
return _.values(descriptions);
},
答案 0 :(得分:0)
我觉得你不能用那个包做你想做的事。如果您查看软件包文档的current limitations,可以看到问题的其他可能解决方案。
您可以按如下方式进行附加过滤:
filter: { 'gender': 'female' }});
但我认为这不会让你只要求独特的选择。
您在上面为try
编写的代码不会执行任何操作。自动填充功能不会使用名为try
的字段。