【发布时间】:2018-03-12 05:44:16
【问题描述】:
我正在使用来自使用 angularjs 的服务器的数据构建一个动态 json。我已将其声明如下。仅当来自服务器的数据在对象数组中有一项时才有效。我应该如何声明它才能动态工作?
$scope.items = [{
id: “”,
locations: [{
name: “”
}]
}]
for (var i=0; i<$scope.data.length; i++)
{
$scope.items[i].id = $scope.data[i].id;
for(var j=0; j<$scope.data[i].locations.length; j++) {
$scope.items[i].locations[j].name = $scope.data[i].locations[j].name;
}
}
这仅在有来自该服务器的一条记录时才有效
【问题讨论】:
-
检查 -
$scope.data.length和$scope.items.length -
我仍在寻找这个问题的最佳答案。
标签: javascript arrays angularjs json ecmascript-5