嗨,我在我的angularjs站点中使用bootstrap ui typeahead。这很好用。我只是想知道,当用户输入列表中没有的内容时,是否可以显示一些类似"No matches found“的文本。
发布于 2015-09-05 20:41:40
typeahead指令包含了一个属性typeahead no-results。
下面是一个示例:
<input type="text" ng-model="asyncSelected" placeholder="Placeholder Text" typeahead="address for address in getLocation($viewValue)" typeahead-no-results="noResults" class="form-control">然后使用ng-if或ng-show显示错误消息。
<div ng-if="noResults">
No Results Found!
</div>要获得更多阅读材料,请务必查看bootstrap-ui docs
发布于 2019-09-10 15:48:50
typeahead-no-results选项不支持多个typeaheads,在我看来非常笨拙。您可能希望显示"No matches found“,而不是显示结果,而不是其他位置。
我被迫对选择时调用的方法中的UibTypeaheadController做了一个非常小的变通:
scope.select = function(activeIdx, evt) {
if (scope.matches.length === 1
&& scope.matches[activeIdx].model != null
&& scope.matches[activeIdx].model.noMatchesFound) {
return;
}此外,当搜索回调中没有匹配项时,我不得不推送一个虚拟对象:
if (matches.length === 0) {
matches.push({
displayProperty: "No matches found",
noMatchesFound: true
});
}https://stackoverflow.com/questions/32396288
复制相似问题