1

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"
   }

]
  }
1
  • Hi, any answer below helpful to you? Commented Jan 29, 2013 at 18:54

5 Answers 5

2

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/

Sign up to request clarification or add additional context in comments.

1 Comment

actually those two json object came was created from this: var jvdetailData = Ext.encode({ details:Ext.pluck(store_jvdtl.data.items, 'data')}); var jvheaderData = Ext.encode({ jvtdata : Ext.pluck(store_jvhdr.data.items, 'data')[0]}); I tried what you did and it didnt work for me
2

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)
};

Comments

1

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);

2 Comments

Ext.pluck is deprecated since ExtJS 4.0.0, use Ext.Array.pluckinstead
Updated according to #Darin Kolev
0

I believe you need the merge method:

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

Comments

0

Here is comparing the function for ExtJS:

Ext.Object.equals(object1, object2)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.