html - 仅当满足某些条件时,如何在AngularJs中显示表格行
问题描述
我从后端获取案例列表,我想根据几个条件显示一些案例,例如每个案例的inspectionStage 字段和数值。我只想在有inspectionStage = 0的行中显示案例。
我努力了:
<tr ng-repeat="qcCase in qcCases | filter: filter.case" ng-if="{{inspectionStage==0}}">
但它不起作用,我也尝试过使用ng-show
under<tr>
标签但它不起作用。这是我的代码sinppet:
<div class="panel-body">
<div class="row">
<div class="col-md-4">
<div ng-cloak style="padding-left: 15px; padding-top: 15px; padding-bottom: 5px;">
<md-input-container class="md-block"> <label>Search Cases</label> <input ng-model="filter.case">
</md-input-container>
</div>
</div>
</div>
<md-content>
<md-tabs md-dynamic-height md-border-bottom>
<md-tab label="Not Started">
<md-content class="md-padding">
<table ng-table="tableParams" class="table table-striped table-bordered table-hover">
<tr ng-repeat="qcCase in qcCases | filter: filter.case">
<td data-title="'#'">{{$index + 1}}</td>
<td data-title="'Case ID'">{{qcCase.id}}</td>
</tr>
</table>
</md-content>
</md-tab>
</md-tabs>
</md-content>
</div>
请注意 -需要filter.case
在<tr>
标签下才能从列表中搜索案例。我想根据inspectionStage 在某处添加一个条件,如果inspectionStage 为0,那么只有该行应该显示该数据。
解决方案
为了达到预期的结果,请使用以下选项,使用带有条件的 ng-ifqcCase.inspectionStage==0
而不是inspectionStage==0
工作代码示例供参考
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.qcCases = [{id: 1, inspectionStage: 0},
{id: 2, inspectionStage: 1},
{id: 3, inspectionStage: 0}]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<table ng-table="tableParams"
class="table table-striped table-bordered table-hover">
<tr
ng-repeat="qcCase in qcCases | filter: filter.case" ng-if="qcCase.inspectionStage==0">
<td data-title="'#'">{{$index + 1}}</td>
<td data-title="'Case ID'">{{qcCase.id}}</td>
</tr>
</table>
</div>
</body>
codepen - https://codepen.io/nagasai/pen/QeGwjg?editors=1010
推荐阅读
- reactjs - Jest 抛出错误“已接收:序列化为相同的字符串”
- postgresql - Codeigniter:如何在 for 循环中增加活动记录?
- android - 我如何才能收到 2 项活动的意向?
- kubernetes - 如何在 Kubernetes 中查看 API 访问日志?
- mysql - 如何优化 SQL 查询?
- c# - 触发 ComboBox SelectedValue 不起作用
- flutter - 'package:flutter/src/painting/_network_image_io.dart':断言失败:第 22 行 pos 14:'url != null':不正确
- sql-server - 如果在 SQL Server 中使用多个插入语句,则为 else
- java - 从 CLI 运行自定义 mojo 时,Maven 无法识别参数
- scikit-learn - ValueError:至少需要一个数组或数据类型 HistGradientBoostingRegressor