我可以在 angular.forEach() 循环中使用字符串变量吗,如下所示:
var variable= "keyname";
angular.forEach($scope.arrCategory[0].variable,function(k,d){
//alert(k);
angular.forEach(k,function(kk, dd){
alert(dd);
});
});
如果这是错误的,我应该如何在循环中使用这个变量?
最佳答案
您应该使用bracket notation通过变量名称访问属性:
var variable = "keyname";
angular.forEach($scope.arrCategory[0][variable], function(k,d) {
angular.forEach(k, function(kk, dd) {
alert(dd);
});
});
关于angularjs - 在 forEach() 循环中使用字符串变量来获取 Angular 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35100071/