MD-项目未在MD-自动完成角料正确更新suggesion列表 [英] md-items is not updating the suggesion list properly in md-autocomplete Angular Material

查看:175
本文介绍了MD-项目未在MD-自动完成角料正确更新suggesion列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MD-自动完成,其中未正确更新响应列表是从服务宿主获得的MD-项目 - Ajax调用

I'm using md-autocomplete, in that md-items which is not updating the response list properly which is obtained from the Service Host - Ajax Call.

HTML源代码code

HTML Source Code

<md-autocomplete flex required
    md-input-name="autocompleteField"
    md-no-cache="true"
    md-input-minlength="3"
    md-input-maxlength="18"
    md-selected-item="SelectedItem"
    md-search-text="searchText"
    md-items="item in querySearch(searchText)"
    md-item-text="item.DisplayName" Placeholder="Enter ID" style="height:38px !important;">
    <md-item-template>
        <span class="item-title">
            <span md-highlight-text="searchText" md-highlight-flags="^i"> {{item.ID}} </span>
            <span> - </span>
            <span md-highlight-text="searchText"  md-highlight-flags="^i"> {{item.Description}} </span>
        </span>
    </md-item-template>
</md-autocomplete>

AngularJS脚本

AngularJS Script

//bind the autocomplete list when text change
function querySearch(query) {
    var results = [];
    $scope.searchText = $scope.searchText.trim();
    if (query.length >=3) {
        results = LoadAutocomplete(query);
    }
    return results;
}

//load the list from the service call
function LoadCPTAutocomplete(id) {
    TestCalculatorService.searchAutocomplete(id).then(function (result) {
        if (result.data != null) {
            $scope.iList = result.data;
        } else {
            $scope.iList = [];
        }
    });
    return $scope.iList;
}

我收到来自服务主机自动完成列表。我正确得到响应,但它不能在正确的用户界面更新

I'm getting the autocomplete list from the Service Host. I'm getting the response properly, but it does not update in the UI properly.

屏幕截图1:

在这里,我在寻找的 8224 ,但它显示的 822 的结果。我调试在Firebug问题,见上面的屏幕截图它显示,该请求的搜索词派的 8224 和我作为一个JSON对象,它是在显示的两个匹配的项目响应下面的屏幕截图2

Here I'm searching for 8224 but it shows the result for 822. I debugged the issue in Firebug, see the above Screen shot it shows, the request was sent for the search term 8224 and I got the response of two matching items as a JSON Object, which is shown in the below Screen Shot 2

响应JSON

在用户界面,它显示的结果是82232,82247,82248,82270.但实际上服务回报是82247和82248。

In UI, it shows the result 82232, 82247, 82248, 82270. But actually Service return is 82247 and 82248.

如何更新项目源在UI的角度材质MD-自动完成?请帮助我。

How to update the Item-source in UI for Angular Material md-autocomplete? Kindly assist me.

问题扶持被张贴在以下链接<一个href=\"http://stackoverflow.com/questions/35646077/manually-call-scope-apply-raise-error-on-ajax-call-error-rootscopeinprog\">Manually调用$ $范围对AJAX调用申请加薪的错误 - 错误:[$ rootScope:inprog]

Supportive Question was posted in the following link Manually call $scope.$apply raise error on ajax call - Error: [$rootScope:inprog]

推荐答案

在下面的帖子标注的答案是正确的按要求。
<一href=\"http://stackoverflow.com/questions/35652828/http-issue-values-cant-be-returned-before-a-promise-is-resolved-in-angular-m/35707185#35707185\">$http承诺在角材料解决之前,不能返回的值MD-自动完成

The Answer Marked in the following post is Correct as per the requirement. $http issue - Values can't be returned before a promise is resolved in Angular Material md-autocomplete


  • 。然后() - 诺API的全部功能,但稍微详细

  • .success() - 没有返回的希望,但是提供了一个简便的语法

不要使用.success(),使用。然后获得更新的结果在UI ...

Don't use .success(), use .then to get the updated result in the UI...

这篇关于MD-项目未在MD-自动完成角料正确更新suggesion列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆