Merge two different json object in extjs

Let's say my first json object is

  "jvtdata":{
    "tranid":"100001",
    "trandate":"Sun Jan 20 2013 00:00:00 GMT+0800 (Taipei Standard Time)",
    "trantype":"f"
  }

and my second data is

 "detail" : [
   {
      "id": "1",
      "obj": "data1"
   },
   {
      "id": "2",
      "obj": "data2"
   },
   {
      "id": "3",
      "obj": "data3"
   }

]

how do I make it like this in extjs 4?

  "jvtdata":{
    "tranid":"100001",
    "trandate":"Sun Jan 20 2013 00:00:00 GMT+0800 (Taipei Standard Time)",
    "trantype":"f",
    "detail" : [
   {
      "id": "1",
      "obj": "data1"
   },
   {
      "id": "2",
      "obj": "data2"
   },
   {
      "id": "3",
      "obj": "data3"
   }

]
  }

Answers


Looking at your comment on another answer, here is what you are looking for(I think?):

var details = Ext.Array.pluck(store_jvdtl.data.items, 'data');
var jvtData = Ext.Array.pluck(store_jvhdr.data.items, 'data')[0];
jvtData["details"] = details;
jvtData = Ext.encode(jvtData);

This is not an ExtJS specific question.

If you truly have two Objects jvtdata and detail (and not a JSON string, which you can easily turn into an Object) you can simply do the following:

jvtdata.detail = detail

EDIT: See console for this fiddle: http://jsfiddle.net/FXT9k/


Ext.apply might be what you're looking for.

var first = {
    "jvtdata":{
        "tranid":"100001",
        "trandate":"Sun Jan 20 2013 00:00:00 GMT+0800 (Taipei Standard Time)",
        "trantype":"f"
    }
};
var second = {
    "detail" : [{
        "id": "1",
        "obj": "data1"
    }, {
        "id": "2",
        "obj": "data2"
    }, {
        "id": "3",
        "obj": "data3"
    }]
};
var merged = {
    jvtdata: Ext.apply(first.jvtdata, second)
};

I believe you need the merge method:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-merge


Here is comparing the function for ExtJS:

Ext.Object.equals(object1, object2)

Need Your Help

How a JAR file running in android calls a executable file running on Windows?

java android automated-tests executable uiautomator

I'm perform some tests with uiautomator and after the device makes some steps, I need to measure the current of it.

Find contact from email (or other information) in Xmpp

android xmpp openfire smack asmack

I am currently working on an Android Application in which XMPP is used for communication between users. Now I need to add a function for importing friends from Facebook or the phone contact-list.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.