const address = [
{
id: 1,
name: '北京市',
children: [
{
id: 11,
name: '海淀区',
children: [
{
id: 111,
name: '中关村',
}
]
},
{
id: 12,
name: '朝阳区',
},
],
},
{
id: 2,
name: '河北省'
}
]
const address = [
{
id: 1,
name: '北京市',
children: [
{
id: 11,
name: '海淀区',
children: [
{
id: 111,
name: '中关村',
}
]
},
{
id: 12,
name: '朝阳区',
},
],
},
{
id: 2,
name: '河北省'
}
]
function getNameById(address, id) {
var rx = new RegExp('"id":'+id +',"name":"(.*?)"');//使用正则
var result = rx.exec(JSON.stringify(address));
if(result!=null)
return result[1];
else
return null
}