我正在尝试将 html 表数据转换成这样的东西: jsFiddle Demo
[{
name: 'Week 1',
data: [33.95, 40.68]},
{
name: 'Week 2',
data: [11.99, 16.66]},
{
name: 'Week 3',
data: [1.96, 0.93]},
{
name: 'Week 4',
data: [0, 1.21]}]
我正在使用的方法:
var Consolelog = $('table tbody tr').map(function() {
var $row = $(this);
return {
name: $row.find(':nth-child(1)').text(),
data: $('td:not(:nth-child(1))', this).each( function(){
$(this).text();
})
};
}).get();
console.log(Consolelog);
alert(Consolelog.toSource());
但是,这给了我这样的东西:
[{
name: "Some Data 1 ",
data: {
length: 4,
prevObject: {
0: ({}),
context: ({}),
length: 1
},
context: ({}),
selector: "td:not(:nth-child(1))",
0: ({}),
1: ({}),
2: ({}),
3: ({})
}},
{
name: "Some Data 1 ",
data: {
length: 4,
prevObject: {
0: ({}),
context: ({}),
length: 1
},
context: ({}),
selector: "td:not(:nth-child(1))",
0: ({}),
1: ({}),
2: ({}),
3: ({})
}}]
任何建议我做错了什么?