PHP 无限极分类
PHP代码
$tree = $this->getTree($data, 0);
public function getTree($data, $pId , $arr=null)
{
$html = '';
foreach($data as $k => $v)
{
if($v['pid'] == $pId){
//父亲找到儿子
if (in_array($v['id'],$arr)) {
// $html .= $v['id'].','$arr;
$html .= "<li><input type='checkbox' value=" . $v['id'] ." checked>".$v['name']."</li>";
$html .= $this->getTree($data, $v['id'],$arr);
} else {
$html .= "<li><input type='checkbox' value=" . $v['id'] .">".$v['name']."</li>";
$html .= $this->getTree($data, $v['id'],$arr);
}
}
return $html ? '<ul>'.$html.'</ul>' : $html ;
}
HTML
<link rel="stylesheet" type="text/css" href="/Public/css/SimpleTree.css"/>
<script type="text/javascript" src="/Public/js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="/Public/js/SimpleTree.js"></script>
<script type="text/javascript">
$(function(){
$(".st_tree").SimpleTree({
click:function(a){
if(!$(a).attr("hasChild"))
alert($(a).attr("ref"));
}
});
});
</script>
<div class="st_tree">
{$tree}
</div>