signmem 发表于 2018-07-24 18:36

求助: javascript 中的输出方法

前提:
从 python (DJANGO) 中获取变量, 变量值如下:
{u'mem_free': [{153108350100: 5571}, {153108350100: 5571}, {153108350100: 5571}, {153108350100: 5571}, {153108350100: 5571}], u'mem_used': [{153108350100: 13070}, {153108350100: 13070}, {153108350100: 13070}, {153108350100: 13070}, {153108350100: 13070}]}
javascript 已经可以获得对应 array

if (title == 'mem')
{
   data1_title = 'mem_free';
   data2_title = 'mem_used';
   $.each(listinfo.data, function(index, item){
      if ( index == data1_title)
      {
          data1_data = item;
..... 其他代码忽略.....
}

当前 data1_data =   [{153108350100: 5571}, {153108350100: 5571}, {153108350100: 5571}, {153108350100: 5571}, {153108350100: 5571}]

但怎么可以组合成为下面格式供 JAVASCRIPT 调用?

key 对应 x: 值
value 对应 y: 值

[
   { x: 1136053800000, y : 65 },
   { x: 1157049000000, y : 95 },
   { x: 1162319400000, y : 68 },
   { x: 1180636200000, y : 28 },
   { x: 1193855400000, y : 34 },
   { x: 1209580200000, y : 14 },
   { x: 1304188200000, y : 11 }
]

当我重新组合之后, 会变成多了 '' 导致数据格式无效。


[
'{ x: 1136053800000, y : 65 }',
'{ x: 1157049000000, y : 95 }',
'{ x: 1162319400000, y : 68 }',
'{ x: 1180636200000, y : 28 }'
]

请问有什么方法可以直接套用?



页: [1]
查看完整版本: 求助: javascript 中的输出方法