angularjs - 如何过滤下拉列表并在角度 js 的选择下拉列表中绑定第一个匹配项
问题描述
我有输入文本框来从下拉选择列表中过滤项目。这工作正常。
但是有两个问题。
- 当数据被填充时,我希望第一项在下拉列表中可见。
- 当我在过滤器框中键入时,列表中的第一个匹配应该显示在下拉控件中。
我如何实现这一目标?
<input type="text" id="fromSearchBox" class="form-control w-auto h-25"
ng-model="SearchEmployee" />
<select class="form-control" ng-model="fromManagerInfo">
<option ng-repeat="emp in employees|filter:SearchEmployee">
{{emp.EmployeeInfo}}
</option>
</select>
解决方案
您可以在 ng-init 上使用 ng-model 设置 selectedItem
<input type="text" ng-init="SearchEmployee = employees[0]" id="fromSearchBox" class="form-control w-auto h-25" ng-model="SearchEmployee" />
对于过滤器,您已经在使用filter
推荐阅读
- tcp - Homekit LAN TCP连接逆向工程IOT设备请求
- sql - WHERE 子句处或附近的语法错误,自然连接
- javascript - 在 Js、React Native 中从 Windows-1252 转换为 UTF-8
- javascript - Jquery addClass 在手机上不起作用
- sql-server - Microsoft SQL Server 2016,T-SQL:根据各个日期获取数据集的日期范围
- python - API返回对象内部的数组如何显示内容-Django
- javascript - 从 HTMLCollection 中删除循环中具有空值的子项
- php - phpmyadmin 中的数据库连接
- python - 如何在不检查 type(x)__name__ 字符串的情况下检查 python c_ubyte_Array 类型?
- azure - 如何通过 CI/CD 管道将 Azure 函数部署到函数应用中?