这是我的功能:
function browsepage_from(starting_node)
{
//record the properties of the object
var account_to_rec = new Array();
var property_name
var properties = $(starting_node).children('div').children("p").each(function(){
property_name = $(this).attr('class').split(' ')[1];
account_to_rec[property_name] = $(this).html();
});
//push the object with properties newly created into a global variable
to_save.push(account_to_rec);
//check if children
if($(starting_node).children('ul'))
{
$(starting_node).children('ul').children("li").each(function(){
browsepage_from($(this))
});
}
else
{
}
}
没什么好看的......
to_save
是一个全局变量:
to_save = new Array();
但是在控制台中,我的数组看起来像这样:
[[]
account_action
"none"
account_code
"000000"
bla bla
[]
account_action
"none"
account_code
"600000"
bla bla
]
如果我使用JSON.stringify(在完成的to_save或每个account_to_rec的递归中),我只得到空括号...
怎么样?
答案 0 :(得分:0)
Probablu错误
var account_to_rec = new Array();
以后再尝试将其用作
中的对象property_name = $(this).attr('class').split(' ')[1];
account_to_rec [property_name] = $(this).html();
也许
var account_to_rec = {};
???