<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var Json = { id: '1', children: [{ id: '2', children: [{ id: '3' }, { id: '4' }] }, { id: '5' }] };
function json(jsontree) {
if ((typeof jsontree == 'object') && (jsontree.constructor== Object.prototype.constructor)) {
var arrey = [];
arrey.push(jsontree);
}
else arrey = jsontree;
for (var i = 0; i < arrey.length; i++) {
var jn = arrey[i];
if (jn.id == "3") {
alert('找到id值是3的啦');
return;
}
if (jn.children && jn.children.length > 0) {
json(jn.children);
}
}
}
json(Json);
</script>
</body>
</html>
遍历树形json
最新推荐文章于 2023-06-28 15:40:19 发布