如何在 angularJS 中为内部 ng-repeat 设置 Where 子句
How to set Where Clause for a inner ng-repeat in angularJS
我有两个 JSON 数组,
$scope.color = [
{
"cInstId": 1,
"cInstTitle": "Blue"
},
{
"cInstId": 2,
"cInstTitle": "Green"
},
{
"cInstId": 3,
"cInstTitle": "Red"
},
{
"cInstId": 4,
"cInstTitle": "Orange"
},
{
"cInstId": 5,
"cInstTitle": "Violet"
}
];
$scope.data = [
{
"id": 1,
"cTitle": "One",
"cInstId": 1
},
{
"id": 2,
"cTitle": "Two",
"cInstId": 2
},
{
"id": 3,
"cTitle": "Three",
"cInstId": 3
},
{
"id": 4,
"cTitle": "Four",
"cInstId": 4
},
{
"id": 5,
"cTitle": "Five",
"cInstId": 4
}
];
现在我需要在 cInstId
中打印所有具有关联 $scope.data
和公共键值的 $scope.color
<div ng-repeat="col in color">
<p>{{ col.cInstTitle }}</p>
<ol>
<li ng-repeat="dataItem in data| **WHERE CLAUSE dataItem.cInstId = col.cInstId** ">
<div>{{ dataItem.cTitle }}</div>
</li>
</ol>
</div>
您可以只使用 ng-if
子句。使用这一行 -
<li ng-if="dataItem.cInstId=== col.cInstId" ng-repeat="dataItem in data">
您可以按如下方式使用 filter
<li ng-repeat="dataItem in data | filter : {cInstId: col.cInstId}">
<div>{{ dataItem.cTitle }}</div>
</li>
以下筛选条件将根据 cIntsId
键筛选 data
数组中的 dataItem
个对象。
filter : {cInstId: col.cInstId}
我有两个 JSON 数组,
$scope.color = [
{
"cInstId": 1,
"cInstTitle": "Blue"
},
{
"cInstId": 2,
"cInstTitle": "Green"
},
{
"cInstId": 3,
"cInstTitle": "Red"
},
{
"cInstId": 4,
"cInstTitle": "Orange"
},
{
"cInstId": 5,
"cInstTitle": "Violet"
}
];
$scope.data = [
{
"id": 1,
"cTitle": "One",
"cInstId": 1
},
{
"id": 2,
"cTitle": "Two",
"cInstId": 2
},
{
"id": 3,
"cTitle": "Three",
"cInstId": 3
},
{
"id": 4,
"cTitle": "Four",
"cInstId": 4
},
{
"id": 5,
"cTitle": "Five",
"cInstId": 4
}
];
现在我需要在 cInstId
$scope.data
和公共键值的 $scope.color
<div ng-repeat="col in color">
<p>{{ col.cInstTitle }}</p>
<ol>
<li ng-repeat="dataItem in data| **WHERE CLAUSE dataItem.cInstId = col.cInstId** ">
<div>{{ dataItem.cTitle }}</div>
</li>
</ol>
</div>
您可以只使用 ng-if
子句。使用这一行 -
<li ng-if="dataItem.cInstId=== col.cInstId" ng-repeat="dataItem in data">
您可以按如下方式使用 filter
<li ng-repeat="dataItem in data | filter : {cInstId: col.cInstId}">
<div>{{ dataItem.cTitle }}</div>
</li>
以下筛选条件将根据 cIntsId
键筛选 data
数组中的 dataItem
个对象。
filter : {cInstId: col.cInstId}