简体   繁体   English

无法从md-autocomplete中的对象数组获取值

[英]Unable to get the value from an array of object in md-autocomplete

I have an array of objects, and Now I am trying to select the data. 我有一个对象数组,现在我正在尝试选择数据。 Enclosed file is a snapshot of the object I am getting in console. 封闭文件是我在控制台中获取的对象的快照。 在此处输入图片说明

I want to get the emailid even if user search by the empid or empname or emailid from the object in autocomplete. 即使用户通过自动完成对象中的对象使用empid或empname或emailid搜索,我也想获取emailid。 But I am unable to retrieve this one when I start typing in md-autocomplete my screen blinks and never gave me list of filter items. 但是,当我开始在md-autocomplete输入内容时,我无法检索到此信息,我的屏幕闪烁并且从没有给我过滤器列表。
Updated code : 更新的代码:

<md-autocomplete flex required
                                md-search-text="searchText"
                                md-input-name="autocomplete"
                                md-search-text-change="searchTextChange(searchText)"
                                md-items="item in search(searchText)"
                                md-item-text="item"
                                md-floating-label="Reporting Manager">
                                    <md-item-template>
                                        <span md-highlight-text="searchText" md-highlight-flags="^i">{{item.empname}}</span>
                                    </md-item-template>
                                </md-autocomplete>

And this is my javascript search() function 这是我的javascript search()函数

$scope.search = function(text){
    var deferred = $q.defer()
    var result = []
    var resolve = function(reportingManager){
      //console.log(reportingManager)
      angular.forEach(reportingManager,function(val){
        //console.log(val)
        angular.forEach(val,function(value){
          //console.log(value)
          if(value.empid.toUpperCase().includes(text.toUpperCase())
            || value.empname.toUpperCase().includes(text.toUpperCase())){
            result.push(value.empname)
            //console.log(result)
          }
        })
      })
      deferred.resolve(result)
    }
    if(text){
      resolve(reportingManager? reportingManager: [])
    }else{
      resolve([]);
    }
    return deferred.promise
  }

reportingManager is an array of arrays which has the objects which i have included in the snapshot. reportManager是一个数组数组,其中包含我包含在快照中的对象。 Any help on this one would be highly appreciable 任何对此的帮助将是非常可观的
Regards 问候

First of all I would like to thank @ Titus for being there for me and walking with me to solve my problem. 首先,我要感谢@ Titus在我身边和我一起解决我的问题。

The issue was not only with Javascript code it was also with CSS. 问题不仅与Javascript代码有关,也与CSS有关。 Since I was trying to put the md-autocomplete in a modal pop up after so many trials the autocomplete suggestions were coming up but it was behind the modal. 由于经过多次试验,我试图将md-autocomplete放入模式弹出窗口中,因此出现了自动完成建议,但它落后于模式。 Here is the working code 这是工作代码

$scope.search = function(text){
        var deferred = $q.defer()
        var result = []
        var resolve = function(reportingManager){
          //console.log(reportingManager)
          angular.forEach(reportingManager,function(val){
            //console.log(val)
            angular.forEach(val,function(value){
              //console.log(value)
              if(value.empid.toUpperCase().includes(text.toUpperCase())
                || value.empname.toUpperCase().includes(text.toUpperCase())){
                result.push(value.emailid)
                //console.log(result)
              }
            })
          })
          deferred.resolve(result)
        }
        if(text){
          resolve(reportingManager? reportingManager: [])
        }else{
          resolve([]);
        }
        return deferred.promise
      }

HTML : HTML:

<div class="md-virtual-repeat-container">
                                    <md-autocomplete flex required
                                    md-search-text="searchText"
                                    md-input-name="autocomplete"
                                    md-search-text-change="searchTextChange(searchText)"
                                    md-items="item in search(searchText)"
                                    md-item-text="item"
                                    md-selected-item="selectedManager"
                                    md-floating-label="Reporting Manager">
                                    <md-item-template>
                                        <span md-highlight-text="searchText" md-highlight-flags="^i">{{item}}</span>
                                    </md-item-template>
                                </md-autocomplete>
                                </div>

Psst ** In case you are trying to get the autocomplete in a pop up don't forget to set the high value for z-index Psst **如果您尝试在弹出窗口中获取自动完成功能,请不要忘记为z-index设置较高的值

And also include the $q in your controller 并在控制器中包含$q

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

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