2015-01-07 2 views
0

우편 번호, 도시, 주를 표시하는 텍스트 상자에 자동 완성 기능이 있습니다. 현재 우편 번호 입력을 시작할 때 [예 : 55414] 자동 완성 기능이 작동하여 관련 지퍼, 도시 및 주를 표시하기 시작합니다. 하지만 도시 이름을 입력하기 시작하면 자동 완성을 트리거하는 방법을 알 수 없습니다. 이 두 가지 트리거가 모두 텍스트 상자에 있어야합니다. 규칙 배열에 다른 규칙을 추가하려고했지만 작동하지 않습니다. ZipCodes 컬렉션에는 _id, 도시, 상태 필드가 있습니다. _id는 우편 번호입니다. 사전에여러 규칙을 사용하여 자동 완성을 실행하려면 어떻게해야합니까?

Template.search.helpers({ settings : function() { return { position: "bottom", limit: 20, rules: [{ collection: ZipCodes, field: "_id", template: Template.userPill }] } }

덕분에

+0

어떤 패키지/라이브러리는 자동 완성을 위해 사용하고 있습니까? – Sasikanth

답변

0

나는 당신이 내가이 답변이 너무 알고 선택 옵션을

Template.search.helpers({ 
 
    settings : function() { 
 
     return { 
 
      position: "bottom", 
 
      limit: 20, 
 
      rules: [{ 
 
       collection: ZipCodes, 
 
       field: "_id", 
 
       template: Template.userPill, 
 
       selector: function(match) { 
 
        var regex; 
 
        regex = new RegExp(match, 'i'); 
 
        return { 
 
         $or: [ 
 
          { 
 
           '_id': regex 
 
          }, { 
 
           'city': regex 
 
          } 
 
         ] 
 
        }; 
 
       }, 
 

 
      }] 
 
     } 
 
    } 
 
}) 
 

0

를 사용할 수있는 경우 meteor-autocomplete 를 사용하는 생각 늦은 시간에,하지만 som에게 도움이 될 수 있습니다. 미래의 사람. 서버 측 publish 기능 안에서이 작업을 수행하십시오.

Meteor.publish('ZipCodesPublication', function(selector, options) { 
    let limitTo = Math.abs(options.limit) > 50 ? 50 : options.limit, 
    defaultSelector = selector._id, 
    regEx = defaultSelector.$regex, 
    regExOptions = defaultSelector.$options, 
    customSeletor = { 
     $or: [ 
      { 
      city: { 
       $regex: regEx, 
       $options: regExOptions 
      } 
      }, 
      { 
      _id: { 
       $regex: regEx, 
       $options: regExOptions 
      } 
      } 
     ] 
     }; 

    Autocomplete.publishCursor(Clients.find(customSeletor), this); 
    this.ready(); 
}); 

그리고 바로이 클라이언트에서 수행

Template.search.helpers({ 
    settings : function() { 
     return { 
      position: "bottom", 
      limit: 20, 
      rules: [{ 
       collection: 'ZipCodes', 
       subscription: 'ZipCodesPublication', 
       field: "_id", 
       template: Template.userPill 
      }] 
     } 
    } 
관련 문제