选择项目后,Angularjs模块“ mgcrea.ngStrap.typeahead”将自动完成的文本替换为id

时间:2018-12-17 13:23:54

标签: angularjs angular-strap

我正在使用包含在其中的模块mgcrea.ngStrap.typeahead

var app = angular.module("foo", ["ng", "mgcrea.ngStrap", "mgcrea.ngStrap.typeahead"]);

<script src="Scripts/angular-strap.min.js" type="text/javascript"></script>
<script src="Scripts/angular-strap.tpl.js" type="text/javascript"></script>

当我使用它时,它会显示类似的命中列表

dropdown

当我选择一个项目时,结果将成为该项目的基础ID 某些客户,我当然不想输出。这是文本框的外观。

textbox afterwards

如何保留文本但将ID作为模型?

html看起来像

<input type="text" class="form-control" ng-model="customer"
  data-animation="am-flip-x" bs-typeahead
  bs-options="item.id as item.name for item in autcompleteCustomers($viewValue)">

js

$scope.autcompleteCustomers = function(input)
{
    var data = { term: input };
    return $http.post("AutoCompleteCustomers", data)
        .then(function(response)
        {
            return response.data;
        });
};

后端提供这样的数据:

a list of hits

0 个答案:

没有答案