我想自定义预输入下拉列表以显示“名称”和“原始”。 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 个)值的自定义模板
定义必须在输入字段中显示的内容
- 将整个对象保留为模型
最佳答案
阿尔弗雷多帕西诺
使用 match.model :)
match.label仅是模型项的显示值。
参见第 43 行
<script type="text/ng-template" id="customTemplate.html">
关于angularjs - Angular-ui typeahead 自定义模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35942304/