【发布时间】:2026-01-21 12:35:01
【问题描述】:
我想自定义预输入下拉菜单以显示“名称”和“原始”。 json源格式为
[
...
{
"_id": "56d0524c07e5a2940eb059c6",
"name": "english name",
"original": "original name",
"__v": 0
},
...
]
正如我在文档中看到的,我尝试了这个自定义模板:
<script type="text/ng-template" id="custom.html">
<a>
<span ng-bind-html="match.label.name | uibTypeaheadHighlight:query"></span>
<small ng-bind-html="match.label.original | uibTypeaheadHighlight:query"></small>
</a>
<input type="text" ng-model="$parent.model.referringCourt" typeahead-template-url="custom.html" uib-typeahead="item.name as item for item in search($viewValue)">
它不起作用。我得到的当前结果是选择我在模型中看到一个字符串,而不是选择的整个对象。 正确的方法是:
使用具有 2 个(或 3 个)值的自定义模板
定义哪个必须显示在输入字段中
- 将整个对象保留为模型
【问题讨论】:
标签: angularjs angular-ui-bootstrap angular-ui-typeahead