简体   繁体   English

角材料自动完成增强

[英]angular material autocomplete enhancement

Hi i follow this guide to my project https://material.angularjs.org/latest/demo/autocomplete and https://www.tutorialspoint.com/angular_material/angular_material_autocomplete.htm 嗨,我按照此指南操作了我的项目https://material.angularjs.org/latest/demo/autocompletehttps://www.tutorialspoint.com/angular_material/angular_material_autocomplete.htm

in the example they load the state first to search a state. 在示例中,他们首先加载状态以搜索状态。 and then you can search the state this was a good example. 然后您可以搜索状态,这是一个很好的例子。

in my case how about when you search a name and there were 6k names or more that was a big problem to load and make my web more slower 以我为例,当您搜索一个名字并且有6k个或更多名字时,如何加载和使我的网络变慢是一个大问题

so i give it a try to create my own. 所以我尝试创建自己的。 getting a resource while searching and this is what i come out. 在搜索时获取资源,这就是我的想法。

here's my view (slim format) 这是我的观点(细格式)

div layout="row"
  md-autocomplete md-item-text="item.name" md-selected-item-change="ctrl.selectedItemChange(item)" md-items="item in ctrl.getMatches(searchText)" md-no-cache="true" md-search-text="searchText" md-selected-item="item" md-floating-label="Client Name" flex=""
    md-item-template
      span md-highlight-flags="^i" md-highlight-text="searchText" 
        | {{item.name}} 

my controller(coffee format) 我的控制器(咖啡格式)

 @getMatches = (searchText) =>
  deferred = $q.defer()
  if  searchText.length >= 2
    name = searchText
    test = Client::Search.query {name: name}, (data) =>
      states = data.clients
      if states.length == 0
        name = searchText + "*"
        test = Client::Search.query {name: name}, (data) =>
          states = data.clients
      $timeout (=>
        deferred.resolve states
        return
        ), 1000
    deferred.promise
  else
    test = []

when i get more than 2 letters in my search my resource will be trigger and will start searching. 当我在搜索中收到2个以上字母时,我的资源将被触发并开始搜索。 my problem if i search long word my web will be get slower. 我的问题是,如果我搜索长词,我的网站会变慢。

additional: when i type every letter my server side will response example if i type uni(for university) the word uni will get to my server side and respond and so on and so on then when i complete the word "university" i have so many resource that cause me to slow 另外:当我键入每个字母时,如果我键入uni(用于大学),则服务器端会做出响应,例如uni会到达我的服务器端并做出响应,依此类推,以此类推,当我完成“ university”一词后,许多资源使我慢下来

enter image description here 在此处输入图片说明

在此处输入图片说明

any idea how can inhance this and more faster??? 任何想法如何可以增强这一点,更快???

Try using ajax call from server side, already answered here 尝试从服务器端使用ajax调用,此处已回答

Angular Material autocomplete with $http call 通过$ http调用Angular Material自动完成

这个链接对我帮助。 如何在AngularJS中编写反跳服务,我使用反跳来增强我的自动完成功能,希望对大家有所帮助,谢谢:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM