angularjs ui引导typeahead不使用异步获取

nwsw7zdq  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(150)

我正在尝试使用angularjs和ui引导实现一个typeahead。我想在typeahead下拉列表中显示的数据是异步获取的。根据 console.log “绿色”和“蓝色”,数据提取正确,但typeahead的行为很奇怪。。。在第一次点击时,例如输入“u”,它不起作用。但输入“u00”似乎有效。输入“ste”无效,下拉列表为空,但获取的数据是正确的。我的印象是,双向装订 this.users 未正确同步。
在发布这个答案之前,我抓取了整个网页,但没有任何效果。我的代码中可能有什么问题?
i package.json我有:

"angular": "~1.7.9"
"angular-ui-bootstrap": "^2.5.6"

html片段是:

<input id="search_user"
           type="text"
           class="form-control"
           uib-typeahead="state as state.publicId for state in ctrl.users | filter:{publicId:$viewValue}"
           ng-model="ctrl.blob"
           ng-change="ctrl.prefetchUsersForTypeahead(ctrl.blob)"
           placeholder="{{'SEARCH_PLACEHOLDER' | translate}}">

js片段:

export default class authRequestController {

      constructor($http, $rootScope, $scope, ModalService, AppUserResource, AuthRequestResource, AuthRequestModal, FileSaver, socket) {
         this.blob = ''
         this.users = []
         ...
      }

      prefetchUsersForTypeahead() {
        let blob = this.blob
        console.log('🟡' + JSON.stringify(blob));
        if(blob === undefined || blob === '') return []
        this.Resource.typeaheadUsers({user: blob}).$promise.then(resource => {
          this.users = resource;  // Not updates correctly the typeahead dropdown
          console.log('🟢' + JSON.stringify(resource));        // Data fetched is OK
          console.log('🔵' + JSON.stringify(this.users[0]));   // Data fetched is OK
        });
      }

    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题