听着,我有一个angular-ui-bootstrap自动完成功能,其中包含填充的公司列表。一旦我开始输入自动填充字段,相应的公司弹出,我选择其中一个,工作正常!
所以,我不知道在uib-typeahead中使用什么,就像我们在ng-options中使用 track by 一样?
我用于angular-ui-bootstrap自动填充字段的代码:
<input type="text" ng-model="loadStopForm.customer" uib-typeahead="company as company.businessName for company in allCompanies | filter:$viewValue | limitTo:8" class="form-control" data-error="Please select a customer" required>
所有公司的JSON数组
[{
"companyId": 1,
"companyName": "Coca Cola",
"companyCode": "COC"
}, {
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}, {
"companyId": 3,
"companyName": "Sprite",
"companyCode": "SPR"
}]
到目前为止,一切正常我能成功找到并选择一家公司,但问题是当我从列表中获取此对象时如何预先选择/预填充字段:
{
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}
我能够收到对象,但无法预填充自动填充字段。请帮我解决这个问题。
谢谢!
答案 0 :(得分:0)
{
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}
将上述值分配给typehead的ng-model,如下所示
$scope.loadStopForm.customer = {
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}
<input type="text" ng-model="loadStopForm.customer" uib-typeahead="company as company.companyName for company in allCompanies | filter:$viewValue | limitTo:8" class="form-control" data-error="Please select a customer" required>