angularjs - 如何为 ui-select 提供一个不变的选择?
问题描述
我有一个包含许多值的可搜索下拉列表。我ui-select
用来过滤用户输入的值。我不想一次显示超过 30 个值。但是,我想通知用户,如果用户继续写入/过滤,还有更多可用数据。你会怎么解决?
'More results...'
我的想法是以某种方式在列表中添加一个额外的禁用元素,如果有超过 30 个项目,它的内容类似于。有什么方法可以提供ui-select
不过滤的恒定选择吗?如果滚动下拉列表,那么很明显还有更多数据但没有显示。
<ui-select ng-model="vm.selectedOption" close-on-select="true" on-select="vm.optionSelected($item)" spinner-enabled="true">
<ui-select-match placeholder="{{'Select option'}}">
<span ng-bind="$select.selected.name"></span>
</ui-select-match>
<ui-select-choices
repeat="option in vm.options"
refresh="vm.loadOptions($select.search)"
refresh-delay="200"
ui-disable-choice="option.isConstantChoice=== true"
>
<div ng-bind-html="option.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
解决方案
在您用于生成的数组中添加一个额外的元素,或者更好的解决方案是将真实数据与 UI 分开,并在该元素后面附加如下内容:
var html='<div ng-if="' + expressionForShowingelement + '">Value</div>',
el = document.getElementById('targetelementId');
angular.element(el).append( $compile(html)($scope) )
然后原始源保持不变,UI 与数据/逻辑分离。注意不要混合单引号和双引号并破坏 HTML。
不要忘记设置id
您append()
稍后定位的目标并禁用元素以供选择。
另外,请记住,如果您要响应 AngularJS 事件之外的事件,则需要调用$apply
.
推荐阅读
- python - Azure Python 部署 - Spacy nomodule 发现异常
- powershell - 具有多个 smtps 时提取主 SMTP 的 Powershell 问题
- java - 循环外临时数组的空间复杂度
- r - 为什么在手动计算和使用 stat_summary 时这两个平均值不匹配?
- f# - 有没有更好的方法在 F#/OCaml 中编写交换函数?
- flutter - 如何在颤动的两个按钮之间留出空间?
- python-3.x - 网页抓取时遍历金融时报页面
- html - 打印html消息几秒钟
- css - 将 sass 变量应用于父级的所有元素
- javascript - 如何确保列表项的文本只有一行?