我有两个 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
}
];
现在我需要打印所有 $scope.color
以及相关联的 $scope.data
以及 cInstId
中的公共(public)键值/p>
<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">
关于arrays - 如何在 angularJS 中为内部 ng-repeat 设置 Where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35424365/