angular.forEach,可以使用函数(键)作为范围扩大

angular.forEach, Possible to use function(key) as scope enlargement?

本文关键字:范围 forEach 可以使 函数 angular      更新时间:2024-01-22
  angular.forEach($scope.selectedPoll.questions, function(value, key) {
                   if (key) { 
   TODO
   if ($scope.selectedPoll.survey_data[i].q1 // here i have q1 
   but i want to put (key)
使用

(键(扩展范围是可能的?

所以它会看起来像这样

if ($scope.selectedPoll.survey_data[i].(key) ?

我的观点是,对于问题中的每个键,我在另一个 if 语句中都有相同的键。

而不是$scope.selectedPoll.survey_data[i].q1,请尝试以下操作:

$scope.selectedPoll.survey_data[i][key]
$scope.selectedPoll.survey_data[i][key]

使用数组表示法动态访问对象属性的方法。我不知道我是否理解你呢?