Javascript ng在链接数据对象中重复
我的角度控制器中有一个Javascript ng在链接数据对象中重复,javascript,angularjs,Javascript,Angularjs,我的角度控制器中有一个节点对象。每个节点都有一个指向下一项的next属性: $scope.Stack = function () { this.top = null; this.rear = null; this.size = 0; this.max_size = 15; }; $scope.Node = function (data) { this.data = data; th
节点
对象。每个节点
都有一个指向下一项的next
属性:
$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;
}
}
}
};
我的问题:有没有一种方法可以使用ng repeat/Angular来迭代像这样的链接数据结构?根据AngularJS文档 表达式中的变量–其中变量是用户定义的循环变量,表达式是范围表达式,提供要枚举的集合
因此,ngRepeat只能用于迭代Javascript“集合”。集合包括数组、贴图、集合和弱贴图。因此,您的问题的答案是否定的,您不能迭代链接结构。ng repeat只能迭代官方JavaScript集合(即数组和键值对)。
$scope.Timeline = new $scope.Stack();