Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度重复循环在maxRows超过限制后如何中断?_Javascript_Angularjs - Fatal编程技术网

Javascript 角度重复循环在maxRows超过限制后如何中断?

Javascript 角度重复循环在maxRows超过限制后如何中断?,javascript,angularjs,Javascript,Angularjs,我在resultData中存储了以下json结构: { "ParentObjects": [ { "objId": "A1", "ChildObjects": [ { "description": "child object1" }, { "descr

我在resultData中存储了以下json结构:

{
    "ParentObjects": [
        {
            "objId": "A1",
            "ChildObjects": [
                {
                    "description": "child object1"
                },
                {
                    "description": "child object2"
                }
            ]
        },
        {
            "objId": "A2",
            "ChildObjects": [
                {
                    "description": "child object3"
                },
                {
                    "description": "child object4"
                },
                {
                    "description": "child object5"
                }
            ]
        },
        {
            "objId": "A3",
            "ChildObjects": [
                {
                    "description": "child object6"
                },
                {
                    "description": "child object7"
                }
            ]
        }
    ]
}
我的html中有两个ng repeat,如下所示:

{{childObj.description}

您可以在ng重复中使用limitTo进行限制


{{childObj.description}

您可以在ng重复中使用limitTo进行限制


{{childObj.description}

Limito在这里不起作用,因为每次ng重复迭代都会创建一个新的作用域,并且Limito将被限制到特定的数组或列表(“ChildObjects”)


{{childObj.description}
可以通过为childObjects数组中的每个项设置索引来实现这一点


{{childObj.description}
$scope.SetIndex=函数(){
var项=0;
angular.forEach($scope.resultData.ParentObjects,函数(值,键){
angular.forEach(value.ChildObjects,函数(value1,键){
value1.index=项目;
项目=项目+1;
});
});
}

Limito在这里不起作用,因为每次ng重复迭代都会创建一个新的作用域,并且Limito将被限制到特定的数组或列表(“ChildObjects”)


{{childObj.description}
可以通过为childObjects数组中的每个项设置索引来实现这一点


{{childObj.description}
$scope.SetIndex=函数(){
var项=0;
angular.forEach($scope.resultData.ParentObjects,函数(值,键){
angular.forEach(value.ChildObjects,函数(value1,键){
value1.index=项目;
项目=项目+1;
});
});
}

否,这不会解决问题。由于我还必须计算渲染的总行数,Limito仅适用于内部tr渲染。请在resultData中使用Limito。它可以工作。不,这不能解决问题。由于我还必须计算渲染的总行数,Limito仅适用于内部tr渲染。请在resultData中使用Limito。它可以工作。
<body ng-app="myApp">
  <div ng-controller="myController">
    <table>
      <tbody ng-repeat="parentObj in resultData.ParentObjects">
        <tr ng-repeat="childObj in parentObj.ChildObjects | limitTo:4">
          <td>{{childObj.description}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</body>
<html ng-app="plunker">

  <body ng-app="plunker">
    <div ng-controller="MainCtrl">
        <table ng-init="SetIndex()">
            <tbody ng-repeat="parentObj in resultData.ParentObjects">
              <tr ng-if="childObj.index < 4" ng-repeat="childObj in parentObj.ChildObjects">
                <td>{{childObj.description}}</td>
              </tr>
            </tbody>
        </table>
         </div>
  </body>

</html>

$scope.SetIndex = function () {
        var item = 0;
        angular.forEach($scope.resultData.ParentObjects, function (value, key) {
            angular.forEach(value.ChildObjects, function (value1, key) {
                value1.index = item;
                item = item + 1;
            });
        });
    }