1

由于我从我的服务器获取数据..我不想从第一个字母开始搜索服务器...我想在 md-autocompleate 操作应该通过正确的排序和最少 10 条记录作为选项之后修复一些最小长度。 ..

目前我的视图页面中有这个

<div ng-controller="ContactChipDemoCtrl as ctrl" layout="column" class="chipsdemoContactChips">

        <md-content class="md-padding autocomplete" layout="column">
        <md-contact-chips
        ng-model="ctrl.contacts"
        md-contacts="ctrl.querySearch($query)"
        md-contact-name="name"
        md-contact-image="image"
        md-contact-email="email"
        md-require-match=""
        filter-selected="ctrl.filterSelected"
        placeholder="To">
      </md-contact-chips><!--md-min-length="3" i wonder y this for-->
      <div ng-repeat="c in ctrl.contacts">{{c.name}}</div>
    </md-content>
  </div>

这在我的控制器搜索查询中是 email-Id

keynotesApp.controller('ContactChipDemoCtrl', DemoCtrl);

function DemoCtrl ($timeout, $q, $http) {
  var self = this;

  self.querySearch = querySearch;
  self.contacts = [];
  self.filterSelected = true;

    /**
     * Search for contacts.
     */
     function querySearch (query) {
      var result;
      if(query) {
        result = loadAndParseContacts().then(function(data) {
          console.log(data)
         return data.filter(createFilterFor(query))
       })
      } else {
        result = []
      }
      return result
    }

    /**
     * Create filter function for a query string
     */
     function createFilterFor(query) {
      var lowercaseQuery = angular.lowercase(query);

      return function filterFn(contact) {
        return (contact._lowername.indexOf(lowercaseQuery) != -1);;
      };

    }
    function parse (data) {
      return data.data.map(function (c, index) {
        var contact = {
          name: c.email,
                      };
          contact._lowername = contact.name.toLowerCase();
          return contact;
        })      
    }
    function loadAndParseContacts() {
      var maxRecs = 10;
      var fields = ('email _id name avatar organization jobTitle');
      var sort = ({email:'ascending'});//this is not working i wonder why
      return $http({
        method: 'GET',
        url: '/users/find',
        params: {fields: fields, maxRecs: maxRecs, sort: sort }
      })
      .then(parse)
    }
  }


md-autocompleate 工作正常... bt 排序、最小长度、最大记录都是我想要的...提前帮助谢谢

4

0 回答 0