1

假设我的第一个 json 对象是

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

]

我如何在 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"
   }

]
  }
4

5 回答 5

2

这不是 ExtJS 特定的问题。

如果你真的有两个对象jvtdatadetail(而不是一个 JSON 字符串,你可以很容易地变成一个对象),你可以简单地执行以下操作:

jvtdata.detail = detail

编辑:查看这个小提琴的控制台:http: //jsfiddle.net/FXT9k/

于 2013-01-23T18:57:29.983 回答
2

Ext.apply可能是您正在寻找的。

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)
};
于 2013-01-25T09:30:31.427 回答
1

查看您对另一个答案的评论,这就是您要寻找的内容(我认为?):

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);
于 2013-01-23T19:56:55.130 回答
0

我相信您需要合并方法:

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

于 2013-01-23T18:44:15.303 回答
0

这里比较ExtJS的函数

Ext.Object.equals(object1, object2)
于 2014-06-19T09:07:15.833 回答