在 ng-repeat 语句中使用 Or 条件

Using Or Condition in ng-repeat statement

如何在 ng-repeat 中使用 Or 条件。我目前有

<div ng-repeat="waterSample in viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE">

有时可以viewRequest.data.REV_SAMPLE_CMQREQUEST。它应该寻找 viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE or viewRequest.data.REV_SAMPLE_CMQREQUEST 我该如何解决这个问题

为了达到预期的结果,使用下面的三元条件检查 属性 在 viewRequest.data 中使用 REV_SAMPLE_CMQREQUEST_WATER_SAMPLE 并根据条件使用 REV_SAMPLE_CMQREQUEST_WATER_SAMPLE 或 REV_SAMPLE_CMQREQUEST

     <div ng-repeat="waterSample in viewRequest.data.hasOwnProperty('REV_SAMPLE_CMQREQUEST_WATER_SAMPLE')? viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE : viewRequest.data.REV_SAMPLE_CMQREQUEST">
{{wareSample}}
      </div>

工作代码示例

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $scope.viewRequest = {
    data: {
      REV_SAMPLE_CMQREQUEST_WATER_SAMPLE : [
        {id: 1, name: "test1"},
        {id: 2, name: "test2"}
      ],
      REV_SAMPLE_CMQREQUEST:[
        {id: 100, name: "ABC1"},
        {id: 200, name: "ABC2"}
      ]
    }
  }
  
  $scope.conditionalArr = $scope.viewRequest.data.hasOwnProperty('REV_SAMPLE_CMQREQUEST_WATER_SAMPLE')? $scope.viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE : $scope.viewRequest.data.REV_SAMPLE_CMQREQUEST
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl"> 

  <div ng-repeat="waterSample in viewRequest.data.hasOwnProperty('REV_SAMPLE_CMQREQUEST_WATER_SAMPLE')? viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE : viewRequest.data.REV_SAMPLE_CMQREQUEST">
    {{waterSample.id}} {{waterSample.name}}
  </div>

</div>



</body>

codepen - https://codepen.io/nagasai/pen/GVZRem?editors=1010

一种方法是使用 ng-show,像这样:

<div ng-show="viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE" 
    ng-repeat="waterSample in viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE">
<div ng-show="!viewRequest.data.REV_SAMPLE_CMQREQUEST_WATER_SAMPLE" 
    ng-repeat="waterSample in viewRequest.data.REV_SAMPLE_CMQREQUEST">

我认为更简单、更简洁的方法是在您的控制器中连接这两个数组,然后在您的 ng-repeat 中使用它。