I'm trying to use ng-repeat to go through a nested tree-like array.

我正在尝试使用ng-repeat来浏览嵌套的树状数组。

Plunkr Here

HTML

HTML

<div layout></div>
<script type="text/ng-template" id="layout">
  <div class="layout" ng-repeat-start="data in data.nodes" ng-include="data.name"></div>
  <div ng-repeat-end>End of repeater</div>
</script>
<script type="text/ng-template" id="box">
  <div class="box">Box</box>
</script>

JavaScript

JavaScript的

var myApp = angular.module('myApp', []);
myApp.directive('layout', function() {

  return {
    templateUrl: 'layout',
    controller: function($scope) {
      $scope.data = {
        'nodes': [
          {
          'name': 'layout',
          'nodes': [{'name': 'box'}, {'name': 'box'}, {'name': 'box'}, {'name': 'box'}]
          }, 
          {
          'name': 'layout',
          'nodes': [{'name': 'box'}, {'name': 'box'}, {'name': 'box'}, {'name': 'box'}]
          }
        ]
      }
    }
  }
})

My problem is that I need a way to figure out when I'm in the last item of a particular level in the array, but since Angular follows recursion by going deep-first, I can't use ng-repeat-start and ng-repeat-end:

我的问题是我需要一种方法来弄清楚当我在数组中特定级别的最后一项时,但是由于Angular通过深度优先跟随递归,我不能使用ng-repeat-start和ng -repeat端:

The expected result, of course, is:

当然,预期的结果是:

How can I know whether I am at the end of a particular level?

我如何知道自己是否处于特定级别的末尾?

1 个解决方案

#1


2

You could use $last to determine when you're at the end of each iteration:

您可以使用$ last来确定每次迭代结束时的时间:

<div ng-show="$last" ng-repeat-end>End of repeater</div>

This is giving me the latter result in your question.

这会在你的问题中给我后一个结果。

更多相关文章

  1. 如何通过ajax将javascript数组传递给YII动作
  2. 在Javascript中将带有空格的字符串数组转换为小写,然后在Webkit中
  3. 返回指定时间段相同间隔数组
  4. JavaScript数组中的唯一计数,按计数排序
  5. Javascript sort()不适用于Chrome中超过10个对象的数组
  6. 获取JavaScript数组元素的最大长度
  7. 对多维数组中的列进行排序
  8. 获取拆分字符串数组的最后一个元素
  9. JS将字符串转换为数组

随机推荐

  1. 第一行代码:AlertDialog
  2. android ndk 纵览
  3. Android Development Notes -1
  4. Android - LayoutInflater 的使用
  5. android 菜单事件处理
  6. Android button 拖动
  7. android:fitsSystemWindows=“true”
  8. android 网络判断
  9. android tv-TV Apps Checklist
  10. android 串口编程