gpt4 book ai didi

javascript - ng-options 默认选项,显示所有选项

转载 作者:行者123 更新时间:2023-12-03 07:56:01 25 4
gpt4 key购买 nike

我有一个 ng-options 选择列表,我希望有一个显示所有选项的默认选项;当您单击列表中的某个项目时,它应该进行过滤;当您单击默认值时,它应该显示所有值。我可以发誓过去我能够使用值设置为“”的选项 html 元素来做到这一点,但这不起作用,有人可以帮我解决这个问题。下面 fiddle 。

http://jsfiddle.net/nzfks0rq/

<select ng-model="todoFilter" ng-options="todo.name as todo.name for todo in todos" class='form-control'>
<option value="">Choose Vendor</option>
</select>
<ul class="unstyled">
<li ng-repeat="todo in todos | filter:{name: todoFilter}">
{{todo.name}}
</li>
</ul>

谢谢

最佳答案

@mrust 是正确的,但在您的情况下,您可以使用简单的搜索逻辑,如该示例提供的

<div ng-init="friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'},
{name:'Juliette', phone:'555-5678'}]"></div>

<label>Search: <input ng-model="searchText"></label>
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchText">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
</tr>
</table>
<hr>

这段代码对于理解如何使用默认过滤器按一个或多个字段组织搜索更重要

<label>Any: <input ng-model="search.$"></label> <br>
<label>Name only <input ng-model="search.name"></label><br>
<label>Phone only <input ng-model="search.phone"></label><br>
<label>Equality <input type="checkbox" ng-model="strict"></label><br>
<table id="searchObjResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friendObj in friends | filter:search:strict">
<td>{{friendObj.name}}</td>
<td>{{friendObj.phone}}</td>
</tr>
</table>

致以诚挚的问候

叶戈尔

关于javascript - ng-options 默认选项,显示所有选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34799421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com