<SCRIPT type="text/javascript">
<!--
var setting = {
data: {
simpleData: {
enable: true
}
}
};
var zNodes =[
{ id:1, pId:0, name:"父节点1 - 展开", open:true},
{ id:11, pId:1, name:"父节点11 - 折叠"},
{ id:111, pId:11, name:"叶子节点111"},
{ id:112, pId:11, name:"叶子节点112"},
{ id:12, pId:1, name:"父节点12 - 折叠"},
{ id:121, pId:12, name:"叶子节点121"},
{ id:22, pId:2, name:"父节点22 - 折叠"},
{ id:223, pId:22, name:"叶子节点223"},
{ id:224, pId:22, name:"叶子节点224"},
{ id:23, pId:2, name:"父节点23 - 折叠"},
{ id:231, pId:23, name:"叶子节点231"},
{ id:232, pId:23, name:"叶子节点232"},
{ id:233, pId:23, name:"叶子节点233"},
{ id:234, pId:23, name:"叶子节点234"},
{ id:3, pId:0, name:"父节点3 - 没有子节点", isParent:true}
];
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});
//-->
</SCRIPT>
我想把里面这个结点的数据换成数据库的,从后台数据库中获取数据,想问下怎么写,有一个 json.jbuider 文件
json.array!(@menus) do |m|
json.id m.id
json.pId m.parent_id
json.name m.name
end
然后我是这样写的,但是数据显示不出来,搞不到了现在,代码如图
<SCRIPT type="text/javascript">
<!--
var setting = {
async: {
enable: true,
type: "get",
dataType:"json",
url:"index.json.jbuilder",
autoParam:["id","name"],
dataFilter: filter
},
data: {
simpleData: {
enable: true,
idKey:"id",
pIdKey:"pId",
rootPId:null
}
}
};
function filter(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i=0, l=childNodes.length; i<l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting);
});
//-->
</SCRIPT>