Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
将一个json中的值推送到另一个json中_Json_Angular_Typescript - Fatal编程技术网

将一个json中的值推送到另一个json中

将一个json中的值推送到另一个json中,json,angular,typescript,Json,Angular,Typescript,我有两个不同的JSON对象 JSON1 [ { title: "Order Rule Violations", type: "FieldView", panel: "expanded", data: [ { label: "Rule Description", type: "text", }, { label: "comme

我有两个不同的JSON对象

JSON1

 [
   {
     title: "Order Rule Violations",
     type: "FieldView",
     panel: "expanded",
     data: [      
       {
         label: "Rule Description",       
         type: "text",
       },
       {  
         label: "comments",       
         type: "inputarea",
       },
     ],
   },
 ]
JSON2

[
  {
    data: [
      {
        value: "00695",
      },
      {        
        value: " ",        
      },
    ],
  },
]
我需要结合,得到一个像这样的结果

[
  {
    title: "Order Rule Violations",
    type: "FieldView",
    panel: "expanded",
    data: [
      {
        label: "Rule Description",       
        type: "text",
        value: "00695",
      },
      { 
        label: "comments",       
        type: "inputarea",
        value: " ",
      },
    ],
  },
]

请告知我如何使用Angular/Typescript实现这一点,这种情况下:

for(var i=0;i<JSON1[0].data.length;i++)
JSON1[0].data[i].value= JSON2[0].data[i].value;

对于(var i=0;i这种情况下:

for(var i=0;i<JSON1[0].data.length;i++)
JSON1[0].data[i].value= JSON2[0].data[i].value;
for(var i=0;i您可以使用嵌套数组迭代每个数组,然后合并两个对象

const json1=[{
标题:“违反订单规则”,
键入:“FieldView”,
小组:“扩大”,
数据:[{
标签:“规则说明”,
键入:“文本”,
},
{
标签:“评论”,
类型:“inputarea”,
},
],
}];
常量json2={
数据:[{
值:“00695”,
},
{
值:“”,
},
]
};
常量json3=json1.map(y=>{
y、 data=y.data.map(
(x,index)=>Object.assign(x,json2.data[index])
);
返回y;
});
log(json3);
您可以使用嵌套数组遍历每个数组,然后合并这两个对象

const json1=[{
标题:“违反订单规则”,
键入:“FieldView”,
小组:“扩大”,
数据:[{
标签:“规则说明”,
键入:“文本”,
},
{
标签:“评论”,
类型:“inputarea”,
},
],
}];
常量json2={
数据:[{
值:“00695”,
},
{
值:“”,
},
]
};
常量json3=json1.map(y=>{
y、 data=y.data.map(
(x,index)=>Object.assign(x,json2.data[index])
);
返回y;
});

log(json3);
我对JSON2做了一些修改,有点像JSON2=[“”、“”、“”、…]和下面的代码 为我工作

var k=0;  
    for(var i=0; i<this.JSON1.length; i++){                  
                      for(var j=0; j<this.JSON1[i].data.length; j++){
                       console.log("j",j);
                        this.JSON1[i].data[j].value = this.JSON2[k];
                        k++;        
                      } 
                    }
var k=0;

对于(var i=0;i我对JSON2做了一点修改,有点像JSON2=[“”,“”,“”,…]和下面的代码 为我工作

var k=0;  
    for(var i=0; i<this.JSON1.length; i++){                  
                      for(var j=0; j<this.JSON1[i].data.length; j++){
                       console.log("j",j);
                        this.JSON1[i].data[j].value = this.JSON2[k];
                        k++;        
                      } 
                    }
var k=0;

对于(var i=0;这不是一个角度特定的问题。它可以通过Javascript或Typescript来完成,具体取决于您使用的是什么?我需要在Typescript中完成这不是一个角度特定的问题。它可以通过Javascript或Typescript来完成,具体取决于您使用的是什么?我需要在Typescript中完成谢谢克里斯的回答。我不会谢谢你的回复,克里斯。我也会尝试一下,适当地使用它