如何使用适当的数据 json 对象预选 Angular-ui-bootstrap 自动完成
How to preselect Angular-ui-bootstrap autocomplete with appropriate data json object
听着,我有一个 angular-ui-bootstrap 自动完成功能,其中包含公司列表。我一开始在自动完成字段中输入内容,就会弹出相应的公司,我 select 其中之一,工作正常!
So, I don't know what to use in uib-typeahead, just like we use track by in ng-options?
我用于 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 allCompanies
数组
[{
"companyId": 1,
"companyName": "Coca Cola",
"companyCode": "COC"
}, {
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}, {
"companyId": 3,
"companyName": "Sprite",
"companyCode": "SPR"
}]
Hitherto, everything works fine I am successfully able to find and select a company, but the problem is how do I make the field preselected / prefilled when I get this object from the list:
{
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}
我可以收到对象,但无法预填自动完成字段。请帮我解决这个问题。
谢谢!
{
"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>
听着,我有一个 angular-ui-bootstrap 自动完成功能,其中包含公司列表。我一开始在自动完成字段中输入内容,就会弹出相应的公司,我 select 其中之一,工作正常!
So, I don't know what to use in uib-typeahead, just like we use track by in ng-options?
我用于 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 allCompanies
数组[{
"companyId": 1,
"companyName": "Coca Cola",
"companyCode": "COC"
}, {
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}, {
"companyId": 3,
"companyName": "Sprite",
"companyCode": "SPR"
}]
Hitherto, everything works fine I am successfully able to find and select a company, but the problem is how do I make the field preselected / prefilled when I get this object from the list:
{
"companyId": 2,
"companyName": "Pepsi",
"companyCode": "PEP"
}
我可以收到对象,但无法预填自动完成字段。请帮我解决这个问题。
谢谢!
{
"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>