我有一个包含元素的数组,
var input=[
{
"count": 1,
"entity": "Company",
"Company": [
{
"sector": "Consumer, Cyclical",
"ticker": "NWY",
"entity": "New York & Co",
"New_York_&_Co": [
{
"count": 1,
"entity": "New York"
}
],
"type": "SCap"
}
]
},
{
"count": 1,
"entity": "Country",
"Country": [
{
"region": "North Americas",
"index": "MEXICO IPC INDEX",
"Mexico": [
{
"count": 1,
"entity": "Mexico"
}
],
"entity": "Mexico",
"currency": "Peso (MXN)"
}
]
},
{
"count": 2,
"entity": "Persons",
"Persons": [
{
"count": 1,
"entity": "Edwin Garay"
},
{
"count": 1,
"entity": "Rosa"
}
]
}];
我正在尝试订购此数据的输出。我想显示像这样的值,
Company-New York & Co, Country-mexico, Persons-Edwin Garay,Rosa
我不需要最后一级中的数据......我写了一个函数,
function generateTree(input) {
if (input == undefined) {
return;
}
else {
for ( var i = 0; i < input.length; i++) {
if(entityName1!=input[i].entity)
{
entityName = input[i].entity;
entityName1 = input[i].entity;
entityName = entityName.replace(/ /g, "_");
alert(entityName);
}
if (input[i][entityName] != undefined) {
generateTreeHTML(input[i][entityName]);
}
}
}}
上面的脚本将打印输出,
Company-New York & Co, NewYork , Country-mexico,mexico, Persons-Edwin Garay,Rosa
我不想要纽约和墨西哥的基本水平。我怎么做?