該代碼在這裏可用:https://plnkr.co/edit/gbbsEnXxVpLsxvtKsDxw?p=preview。過濾器filter: { a : 'x' }
有效,只顯示一行。帶有「或」條件的AngularJs過濾器?
問:
- 看來
filter: { a : 'xxx' }
比賽只要文本包含字符串xxx
在a
任何文本。如果我想做精確匹配怎麼辦? - 如何實現:顯示所有行如果
a = 'xxx' or b = 3
不能使用c
? - 也許最好在`model.dashbardRows上使用javascript代碼?
dashboard.component.js
(function() {
'use strict';
angular.module('testModule', [])
.component('dashboard', {
templateUrl: 'dashboard.component.html',
controllerAs: 'model',
controller: [controller]
});
function controller() {
var model = this;
model.dashboardRows = [
{a:'xxx', b:1, c:'ss'},
{a:'yyy', b:2, c:'tt'},
{a:'zzz', b:3, c:'uu'}];
}
})();
dashboard.component.html
<div>
Test
<table>
<tr ng-repeat="i in model.dashboardRows | filter: { a : 'x' }">
<td>{{i.a}}</td>
<td>{{i.b}}</td>
</tr>
</table>
</div>
我更新的問題,並添加到列表中的另一個屬性'C',我不想'C'比較時使用。 – ca9163d9