jquery合并两个对象

前端之家收集整理的这篇文章主要介绍了jquery合并两个对象前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将jquery对象合并在一起

我有

{
  "merchantcontract":"Ready Reserve Foods 10104.01","merchantcontractid":"c4253769-5a57-e111-b935-00155d010302","smi_transactiondate":"\/Date(1332140400000)\/","smi_glamount2":15.2600,"smi_transactionclass":180870001,"smi_transactionclassname":"Residual Agent Commission","smi_contractprodcutidname":"Traditional","smi_agentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5","smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
 },{
  "merchantcontract":"Ready Reserve Foods 10104.01","smi_glamount2":2.6000,"smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
     }

我想拥有

{
      "merchantcontract":"Ready Reserve Foods 10104.01","smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
      },{
      "merchantcontract":"Ready Reserve Foods 10104.01","smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
       }

    {"merchantcontract":"Ready Reserve Foods 10104.01"{

      "merchantcontractid":"c4253769-5a57-e111-b935-00155d010302","smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
   },{

      "merchantcontractid":"c4253769-5a57-e111-b935-00155d010302","smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
   }
}

所以两个对象都在一个对象之下。我可能有两个以上的对象。

这些对象是用jquery中的每一个创建的。

我不知道如何开始这个。

解决方法

jQuery的 $.extend会做你想要的
//merging two objects into new object
var new_object = $.extend({},object1,object2);

//merge object2 into object1
$.extend(object1,object2);
原文链接:https://www.f2er.com/jquery/182130.html

猜你在找的jQuery相关文章