arrays - 如何在 angularJS 中为内部 ng-repeat 设置 Where 子句

标签 arrays angularjs angularjs-ng-repeat where-clause 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
    }
];

现在我需要打印所有 $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/

相关文章:

结构中动态数组中结构中动态分配数组的 C 语法

java - 这个三维数组中存在多少个引用?

javascript - 如何通过对象数组运行 forEach 并为具有空字符串的对象属性设置值?

javascript - AngularJS 中的 jQuery 触发器等效项

css - 使用 Flexbox 挤压 ng-repeat 中的元素 - angular.js/flexbox

javascript - 如何在javascript中使用这个多维数组

javascript - AngularJS - 使用 angularjs 拖放列表库时没有在 html 页面中获取任何内容

javascript - 将 Angular 模态数据传递给主 Controller

javascript - AngularJS 中的动态 ng-repeat

javascript - 如何通过匹配 ng repeat 中数组中的键来填充下拉列表?