Py学习  »  Jquery

将数组传递给jQuery每个函数以重新格式化数据

Matts • 5 年前 • 1491 次点击  

我有一组Json数据,需要重新格式化。

数据作为1对象的一部分按行进行如下结构:

"2019-12-27": Object{'a':'1', 'b':'2', 'c':'3', 'd':'4'} 

我想解析每一行,使其与此(或数组)类似,并将所有行合并为一个对象:

["2019-12-27", "1", "2", "3", "4"]

这是我尝试使用$的代码。每个函数都可以工作,但都失败了,因为数组不在内部函数的作用域内。- TypeError: parsed[count] is undefined 有没有办法把解析后的数组从外循环传递到内循环?

parsed = [];
var count = 0;
$.each(data, function(k, outer) {
  count += 1;
  parsed[count][] = k;
  $.each(outer, function(i, inner) {
    parsed[count][] = i;
    });
});
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51988
 
1491 次点击  
文章 [ 2 ]  |  最新文章 5 年前