Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将ID数组与带下划线的对象数组嵌套属性进行比较_Javascript_Arrays_Underscore.js - Fatal编程技术网

Javascript 如何将ID数组与带下划线的对象数组嵌套属性进行比较

Javascript 如何将ID数组与带下划线的对象数组嵌套属性进行比较,javascript,arrays,underscore.js,Javascript,Arrays,Underscore.js,我正在处理一个不使用jquery的项目。我一直在使用下划线或香草javascript。这是我拿的一个小东西。 我需要将locationId的tmpTripsArry嵌套属性与successfullIdArray进行比较,并返回匹配的对象和 isSubmitLocationSuccess 变为真 我没有得到任何错误,但它没有做我需要它做的事情。谢谢喜欢简单地使用下划线 var matchingObjs = tmpTripsArry.filter( function(val){ if ( su

我正在处理一个不使用jquery的项目。我一直在使用下划线或香草javascript。这是我拿的一个小东西。

我需要将locationId的tmpTripsArry嵌套属性与successfullIdArray进行比较,并返回匹配的对象和

isSubmitLocationSuccess

变为真

我没有得到任何错误,但它没有做我需要它做的事情。谢谢喜欢简单地使用下划线

var matchingObjs = tmpTripsArry.filter( function(val){
  if ( successfullIdArray.indexOf( val.routeLocations.locationId ) != -1 )
  {
    val.routeLocations.isSubmitLocationSuccess = true;
  }
  return successfullIdArray.indexOf( val.routeLocations.locationId ) != -1 ;
}) 
如果需要返回所有对象,则使用forEach

tmpTripsArry.forEach( function(val){
  if ( successfullIdArray.indexOf( val.routeLocations.locationId ) != -1 )
  {
    val.routeLocations.isSubmitLocationSuccess = true;
  }
}) 
现在
tmpTripsArry
本身具有修改后的值。

var matchingObjs = tmpTripsArry.filter( function(val){
  if ( successfullIdArray.indexOf( val.routeLocations.locationId ) != -1 )
  {
    val.routeLocations.isSubmitLocationSuccess = true;
  }
  return successfullIdArray.indexOf( val.routeLocations.locationId ) != -1 ;
}) 
如果需要返回所有对象,则使用forEach

tmpTripsArry.forEach( function(val){
  if ( successfullIdArray.indexOf( val.routeLocations.locationId ) != -1 )
  {
    val.routeLocations.isSubmitLocationSuccess = true;
  }
}) 

现在
tmpTripsArry
本身已经修改了值。

太好了!而且我忘了提到我需要返回所有的对象,即使没有匹配的idsgreat!而且我忘了提到我需要返回所有的对象,即使没有匹配的ID