B.B*_*dan 2 arrays where-clause angularjs angularjs-ng-repeat angularjs-filter
我有两个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
}
];
Run Code Online (Sandbox Code Playgroud)
现在我需要打印与公共密钥值$scope.color相关联的所有内容$scope.datacInstId
<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>
Run Code Online (Sandbox Code Playgroud)
你可以使用just ng-if子句.使用此行 -
<li ng-if="dataItem.cInstId=== col.cInstId" ng-repeat="dataItem in data">
Run Code Online (Sandbox Code Playgroud)
您可以使用filter如下
<li ng-repeat="dataItem in data | filter : {cInstId: col.cInstId}">
<div>{{ dataItem.cTitle }}</div>
</li>
Run Code Online (Sandbox Code Playgroud)
以下过滤条件将根据键过滤数组中的dataItem对象.datacIntsId
filter : {cInstId: col.cInstId}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9591 次 |
| 最近记录: |