问题描述
我有一个非常棘手的错误。
我将数据传递给函数。 函数要做的就是获取该数据,并确保该数据在另一个页面上不存在。 另一页上的数据是一个数组,如果其中没有任何内容,则为undefined。 我想做的事情如下:
if($scope.profile.x.VALUE_IN_UNDEFINED_ARR_X === undefined)
{
   //AKA theres nothing in the profile yet...add to users profile
}
else
{
  if($scope.profile.x.name === myData.name)
  {
    //now theres a duplicate found
  }
  else
  {
    //add to users profile
  }
}
我似乎无法使这种工作。 对我来说,它总是在第一个if语句(未定义)中执行代码。 然后,它会不断添加重复项。
我希望你们能帮助我写一个循环为我解决这个问题。
谢谢
1楼 
  
    jperelli 
    1 
   已采纳 
    2015-08-07 05:25:24
  
 
  
     使用typeof检查未定义 
typeof $scope.profile.x.VALUE_IN_UNDEFINED_ARR_X == 'undefined'
 
     另外,“配置文件中没有任何内容”可以解释为“ $scope.profile未定义”,如果是,则应检查此 
typeof $scope.profile == 'undefined'