怎么从数据库读取生成json显示成二级数型
ztree吧
全部回复
仅看楼主
level 1
Ruifly 楼主
这个是表内容
<?php
$mysqli = new mysqli("localhost","root","root","jquery_demo");
if($mysqli->connect_error){
die("Connect Error");
}
$mysqli->query("set names utf8");
$query="select * from ztree_menu";
if($result = $mysqli->query($query)){
$arr=array();
while($row=$result->fetch_assoc()){
array_push($arr, array('id' => $row['id'], 'pId' => $row['pId'], 'name' => $row['name'], 'isParent'=>true));
}
$result->free();
}
$mysqli->close();
$json_arr=json_encode($arr);
header("Content-Type:text/json");
echo $json_arr;
上面是php代码生成用son_encode将数组转换成json格式
var setting_json = {
async: {
enable: true,
url:"../asyncData/ZZgetNodes.php"
}
};
html就用了上面这些
这么显示admin是一级 其他都是二级的样子
对autoParam ,otherParam不理解啊
希望多些通过数据库动态加载的例子
2012年06月02日 08点06分 1
level 1
Ruifly 楼主
array_push($arr, array('id' => $row['id'], 'pId' => $row['pId'], 'name' => $row['name'], 'isParent'=>true));
'isParent'=>true是我自己加上的 这样的话变成N层了。。

2012年06月02日 08点06分 2
level 1
Ruifly 楼主
更正
用json_encode将数组转换成json格式
怎么显示admin是一级 其他都是二级的样子
2012年06月02日 08点06分 3
level 1
Ruifly 楼主
setting中加个
data : {
simpleData:{enable:true}
}
就行了
还是不理解 autoParam otherParam的作用 加不加没啥区别啊
2012年06月02日 09点06分 4
level 11
呵呵,看来自己都搞定了。
关于 autoParam otherParam 你完全可以看看 异步加载的 Demo,然后监控每次 ajax 的提交参数内容,再配上 API 文档看看就知道啦!
2012年06月02日 12点06分 5
1