angularJS 使用数组类型 (?) of-model 进行过滤
angularJS filter using array type(?) ng-model
我想让过滤器只在一个元素上工作。
为了制作过滤器,我搜索了 SO,并找到了制作它的方法。
But I used 'select' tag to choose element applies to filter, I got problem when selected value is NULL.
<div class="input-group">
<select class="form-control" ng-model="setParam">
<option value="">All</option>
<option value="atName">Name</option>
<option value="atComp">Company</option>
<option value="atDep">Department</option>
<option value="atPos">Position</option>
<option value="atTel">Tel</option>
<option value="atEmail">Email</option>
</select>
</div>
<div class="input-group">
<span>
<input type="text" class="form-control" ng-model="atParam[setParam]">
</span>
<tr data-ng-repeat="row in attendees | filter : atParam">
问题是当所选值为 NULL 时没有任何显示。
除了 NULL 之外的一切都很好。解决了怎么办?
或者,还有其他搜索方法吗?谢谢!
我想你的要求是当你select ALL
所有的记录都应该显示。但是你得到 none.
为此,您需要根据 setParam
添加 condition
到 filter
<tr data-ng-repeat="row in attendees | filter : setParam ? atParam : ''">
这是做什么的,
- 它会先搜索setParam。
- 如果是
not null
则使用你的atParam
条件
- 如果为空则过滤
empty string
从而显示all records
我想让过滤器只在一个元素上工作。 为了制作过滤器,我搜索了 SO,并找到了制作它的方法。 But I used 'select' tag to choose element applies to filter, I got problem when selected value is NULL.
<div class="input-group">
<select class="form-control" ng-model="setParam">
<option value="">All</option>
<option value="atName">Name</option>
<option value="atComp">Company</option>
<option value="atDep">Department</option>
<option value="atPos">Position</option>
<option value="atTel">Tel</option>
<option value="atEmail">Email</option>
</select>
</div>
<div class="input-group">
<span>
<input type="text" class="form-control" ng-model="atParam[setParam]">
</span>
<tr data-ng-repeat="row in attendees | filter : atParam">
问题是当所选值为 NULL 时没有任何显示。 除了 NULL 之外的一切都很好。解决了怎么办? 或者,还有其他搜索方法吗?谢谢!
我想你的要求是当你select ALL
所有的记录都应该显示。但是你得到 none.
为此,您需要根据 setParam
condition
到 filter
<tr data-ng-repeat="row in attendees | filter : setParam ? atParam : ''">
这是做什么的,
- 它会先搜索setParam。
- 如果是
not null
则使用你的atParam
条件 - 如果为空则过滤
empty string
从而显示all records