javascript - 将一个数组项调用到另一个数组中

标签 javascript angularjs

我遇到了以下函数(或方法,我不知道该函数的正确名称是什么):

function getRowArray($scope, object, i){    
  i = i + 1;
  var item = {};
  var data = [];
  var id = -1;    

  if ($scope.selectedType !== undefined) {
    id = $scope.selectedType.id;
  }    

  var rating = getRating($scope, object, id);    
  item['name'] = $scope.objectInfo[object]['name'];
  item['objectId'] = rating.objectId;
  item['hideRating'] = parseInt($scope.objectInfo[object].hideControls) & 1;   
  item['addInfo'] = rating.addInfo;   
  item['rating'] = rating.value;    
  item['ratingId'] = rating.id;

  for (var i in $scope.objectInfo[object].childs) {        
    if ($scope.objectInfo[object].childs[i] == object){
        continue;
    }

    data.push(getRowArray($scope, $scope.objectInfo[object].childs[i], i));
  }    
  item['data'] = data;
  return item;
}

function getTypeRow($scope, oobject, otype){

  var item = {};
  var data = [];
  var rating = getRating($scope, oobject.id, otype.id);

  item['name'] = otype.name;
  item['objectId'] = rating.objectId;
  item['typeId'] = rating.typeId;
  item['ratingId'] = rating.id;
  item['addInfo'] = rating.addInfo;
  item['rating'] = rating.value;
  // item['hideRating'] = parseInt($scope.objectInfo[object].hideControls);

  return item;
}

我想在第二个项目中使用第一个项目中的 hideRating 项目,我尝试并添加了注释行,但我收到一个错误,它表示该对象未定义,是这样错误的还是我遗漏了某些内容?提前致谢

最佳答案

object 未定义,因为它未初始化;函数 getTypeRow 的参数列表中未指定它。参数列表中的oobject应更正为object:

// Correct 'oobject' to 'object'
function getTypeRow($scope, object, otype){

  var item = {};
  var data = [];
  // Correct 'oobject' to 'object'
  var rating = getRating($scope, oobject.id, otype.id);

  ...
}

关于javascript - 将一个数组项调用到另一个数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35095711/

相关文章:

c# - 在 javascript 中循环 C# 列表

javascript - 带有 typescript 的 AngularJS : this resolved differently in service and config constructor

javascript - Angular 模态未显示

javascript - Phonegap 未在 Angularjs 指令内触发 GoogleMaps v3 domListener 函数

javascript - 当动态添加对象的元素时,我想在 JSON 对象内部循环 |AngularJS

javascript - 有没有一种方法可以使用类似于 contenteditable 的文本区域的用户提交值来更新 DOM?

javascript - 我可以在 javascript 中提供 me/that/self = this 的原型(prototype)定义吗?

javascript - 在 javascript 序列表达式中声明变量

java - JSF1064 : Primefaces can't load resources

javascript - 经常使用 $scope.$apply() 是一种好习惯吗?