上代码:
for (var i = 1; i < 7; i++) { var res='res'+i; $scope.res=XXXX; };
变量名是由字符串res加i构成的,就是res1--res6;如何在$scope之后连接一个拼接的变量名呢?$scope.res+i或者$scope[res+i]这样都是不行的
感谢回答:最终的答案是不能点.连接变量
ringa_lee
$scope[res] = xxxxx;
for (var i = 1; i < 7; i++) {
var res='res'+i; $scope[res]=i;
}
首先 res应该是个数组,$scope.res=[];
for (var i = 1; i < 7; i++) {$scope.res.push('res'+i);}
大概这样写。
$scope["res"+i]这样写就可以了
$scope[res] = xxxxx;
for (var i = 1; i < 7; i++) {
}
首先 res应该是个数组,
$scope.res=[];
for (var i = 1; i < 7; i++) {
$scope.res.push('res'+i);
}
大概这样写。
$scope["res"+i]这样写就可以了