Mar*_*oli 0 javascript jquery json
我有这个json数据
{
"default": [
[
1325876000000,
0
],
[
1325876000000,
0
],
[
1325876000000,
0
],
[
1325876000000,
0
]
],
"direct": [
[
1328196800000,
0
],
[
1328196800000,
100
],
[
1328196800000,
0
],
[
1328196800000,
0
]
],
"Sales": [
[
1330517600000,
0
],
[
1330517600000,
0
],
[
1330517600000,
91
],
[
1330517600000,
0
]
],
"Support": [
[
1332838400000,
0
],
[
1332838400000,
0
],
[
1332838400000,
0
],
[
1332838400000,
0
]
]
}
Run Code Online (Sandbox Code Playgroud)
我想将其更改为以下格式:
data = [{
label: 'defaul',
data: the array here
}, {
label: 'name',
data: the array here
}, {
label: 'name',
data: the array here
}, {
label: 'name',
data: the array here
}];
Run Code Online (Sandbox Code Playgroud)
在过去,我这样做:
var thearray = result.default.
var theOtherArray = result.direct
...
..
and so on
Run Code Online (Sandbox Code Playgroud)
它工作正常,因为我已经知道标签的名称.我的意思是标签的名称是静态的.
但现在它们很动态,所以我不知道标签的名称.
我该怎么办?
我知道我必须使用
var data = [];
$.each(result, function (index, value) {
var obj = {};
obj.label = SOMETHING
obj.data = result[label]
data.push(obj);
}
Run Code Online (Sandbox Code Playgroud)
但如何获得 SOMETHING
将对象映射到数组中
var data = $.map(result, function(arr,key) {
return {label: key, data: arr};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
593 次 |
| 最近记录: |