2015-09-07 68 views
0

我尝试在我的应用中执行下拉列表。首先我使用流星,所以这是特定类型的应用程序:) 第二件事是我使用sebdah/meteor-autocompletion包,因为我希望我的结果以特定的方式排序和限制。自动完成下拉菜单中的组结果[流星]

我需要的最后一件事是对我的结果进行分组。 例如:如果我有2个名为“blah”的产品,我想在我的下拉列表“autocompletion”列表中仅获得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 

     }, 


}); 

我需要使用的功能,可以在这里我的组 “说明”。

我试图做到这一点的帮手,我得到它我的屏幕上,但说实话,我不知道如何将它放入我的下拉:(

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

我不认为你。可以做你想要与包什么?如果你有看包文件的current limitations,你可以看到其他可能的解决方案,您的问题

你可以做addtional过滤如下: filter: { 'gender': 'female' }}); 但我不我不认为这会让你只要求唯一的选择,

您上面为try所写的代码将不会执行任何操作。自动填充不会占用try的字段。

+0

我明白。我做了“尝试”尝试(:P)在我的屏幕上以HTML文件形式返回集合,并且该代码可以工作 - 它会分组。但我不想让它在我的屏幕上,只想在我的“自动完成下拉列表”中:) – Bart