angular-ui 预先输入自定义模板
angular-ui typeahead custom template
我想自定义预输入下拉列表以显示 "name" 和 "original"。
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">
看起来是我自己解决的,实际上"Custom templates for results"这个例子正是我要找的。解决方案是像那样过滤源
uib-typeahead="item as item.name for item in search($viewValue) | filter:{name:$viewValue}"
我想自定义预输入下拉列表以显示 "name" 和 "original"。 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">
看起来是我自己解决的,实际上"Custom templates for results"这个例子正是我要找的。解决方案是像那样过滤源
uib-typeahead="item as item.name for item in search($viewValue) | filter:{name:$viewValue}"