流星自动完成中的预选/默认值

时间:2020-10-14 06:51:28

标签: javascript meteor autocomplete

我正在使用https://github.com/Meteor-Community-Packages/meteor-autocomplete

我想知道如何在自动完成输入文本中预选择/预填充一个值。如果不可能,是否有任何方法可以设置默认值? HTML value =“ default”不起作用。

我正在尝试在电子邮件撰写者的“抄送”,“密件抄送”字段中使用它。默认情况下,输入字段会选择一些默认用户(视情况而定),但可以使用自动完成搜索来更改它。

1 个答案:

答案 0 :(得分:0)

这是我的代码(很抱歉,无法进行编辑,因此从我的其他帐户进行了回复)

settings() {
return {
  position: 'bottom',
  limit: 80,
  rules: [
    { // token: '',
      collection: Subscribers,
      sort: true,
      field: 'status',
      matchAll: true,
      filter: { status: { $ne: 'deleted' } },
      template: Template.standardSubscribers,
      selector(match) {
        let regex;
        regex = _.map(match.split(' '), function(key) { return new RegExp('^' + key, 'i'); });
        return {
          '$or': [
            { 'firstName': { '$in': regex } },
            { 'lastName': { '$in': regex } },
            { 'email': { '$in': regex } },
            { 'address': { '$in': regex } },
            { 'secondaryEmail': { '$in': regex } }, 
            { 'businessName': { '$in': regex } }
          ]};
      },
    }
  ]
};

},

<template name="standardSubscribers">
<span class="">{{businessName}} {{#if isBusinessName businessName}} -- {{/if}} {{firstName}} {{lastName}} -- {{email}} -- {{secondaryEmail}} -- {{status}} -- {{address}}</span>
'autocompleteselect #email-to' (event, template, doc) {
if (doc.businessName) {
  event.target.value = doc.businessName + '<' + doc.email + '> --- ' + doc.status;
} else {
  event.target.value = doc.firstName + ' ' + doc.lastName + '<' + doc.email + '> --- ' + doc.status;
}

},

{{> inputAutocomplete settings=settings style="width: 73%" value="yogesh" id="email-cc" class="form-control" name="emailCC"  autocomplete="off"  }}