2015-07-19 36 views
4

我的Angular控制器内有一个Node对象。每个Nodenext属性,它指向下一个项目:链接数据对象中的ng-repeat

$scope.Stack = function() { 
     this.top = null; 
     this.rear = null; 
     this.size = 0; 
     this.max_size = 15; 
    }; 


    $scope.Node = function (data) { 
     this.data = data; 
     this.next = null; 
     this.previous = null; 
    }; 

    $scope.Stack.prototype.pushUp = function (data) { 
     for (i = 0; i < data.items.length; i++) { 
      if (data.items[i]) { 

       var node = new $scope.Node(data.items[i]); 
       if (node) { 
        node.previous = this.top; 

        if (this.top) { 
         this.top.next = node; 
        } 

        this.top = node; 

        // if first push, the set the rear 
        if (this.size == 0) { 
         this.rear = node; 
        } 

        this.size += 1; 
       } 
      } 
     } 

    }; 

创建对象:

$scope.Timeline = new $scope.Stack(); 

我的问题:有没有办法来遍历这样的链接的数据结构采用NG-重复/角?

+1

ng-repeat只能迭代官方JavaScript集合(即数组和键值对)。 – Claies

回答

1

按照AngularJS文档,在表达

变量 - ,其中变量是用户定义的循环变量和表达是一个范围表达式,给出的收集来枚举。

因此,ngRepeat只能用于迭代Javascript“集合”。集合包括数组,地图,集合和WeakMaps。所以你的问题的答案是否定的,你不能迭代一个链接结构。