日期:2014-05-16 浏览次数:20388 次
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js"></script> <script type="text/javascript"> var drres={ categories:[ {categories_id:'4',parent_id:'0'}, {categories_id:'6',parent_id:'4'}, {categories_id:'7',parent_id:'6'} ] } //获取目录树数组,如['4','6','7'] function get_upper_categories(cid,arr){ var arr=arr||[]; var a=drres.categories.filter(function (n,i){ return n.categories_id==cid; }); if(a.length>0){ arr.unshift(cid); get_upper_categories(a[0]['parent_id'],arr); }else{ return arr; } } var tree=get_upper_categories('7'); alert(tree); </script>