开发者

How do I extend a json object with jquery extend?

开发者 https://www.devze.com 2023-01-23 07:53 出处:网络
var dataset = {\"read_data\":[{\"date\":\"2010\\/11\\/02 03:30:05\",\"value\":\"2\"}, {\"date\":\"2010\\/11\\/02 03:30:06\",\"value\":\"1\"}]};
var dataset = {"read_data":[{"date":"2010\/11\/02 03:30:05","value":"2"},
                                {"date":"2010\/11\/02 03:30:06","value":"1"}]};

var append = {"read_data":[{"date":"2010\/11\/02 03:30:07","value":"3"},
                           {"date":"2010\/11\/02 03:30:08","value":"4"}]};

I have two data objects like these two. How do 开发者_运维百科I use the JQuery.extend(); to merge them together? so that they look like this so that :

dataset === {"read_data":[{"date":"2010\/11\/02 03:30:05","value":"2"},
                            {"date":"2010\/11\/02 03:30:06","value":"1"},
                            {"date":"2010\/11\/02 03:30:07","value":"3"},
                            {"date":"2010\/11\/02 03:30:08","value":"4"}]};

All the methods contained in this site is not working at all.


jQuery.extend overwrites members with same names and does not support array merging. You'll need to do:

$.merge(dataset.read_data, append.read_data);
0

精彩评论

暂无评论...
验证码 换一张
取 消