jQuery MiniUI
标题:
lazytree 用loadList绑定,然后onbeforeload事件会死循环
[打印本页]
作者:
insony@qq.com
时间:
2023-5-23 16:48:29
标题:
lazytree 用loadList绑定,然后onbeforeload事件会死循环
小弟最近要用lazytree,因为项目原因不可以用url,需要用loadList绑定数据,但是在
onbeforeload
=
"
onBeforeTreeLoad
"的时候一直死循环,不知道怎么处理,麻烦帮忙看看,下面是源代码,其中
getFileForlderURL,
getFileForlderByParentForldId
是我方erp的api接口地址。
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="website/res/js/boot.js" type="text/javascript"></script>
<!-- <script src="website/res/constant.js" type="text/javascript"></script> -->
<script src="website/res/js/common.js" type="text/javascript"></script>
<link href="website/res/frame.css" rel="stylesheet" type="text/css" />
<link href="website/res/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="form1">
<div class="navbar">
<div class="navbar-header">
<div class="navbar-brand"></div>
</div>
</div>
<div id="layout1" class="mini-layout" style="width:100%;height:100%;">
<div title="文件夹" region="west" width="300" showSplitIcon="true">
<ul id="tree1" class="mini-tree" style="padding:5px;" showTreeIcon="true" textField="FNAME"
idField="id" parentField="parentid_id" resultAsTree="false" onbeforeload="onBeforeTreeLoad"
expandOnNodeClick="true" expandOnLoad="0">
</ul>
</div>
</div>
<script type="text/javascript">
mini.parse();
//tree
function firstTreeLoad() {
var jsonObj =
{
"parameter": "parameter"
}
//加载文件夹树
mydata = null;
fnWebApiClient(getFileForlderURL, jsonObj)
if (mydata != null && mydata.length > 0) {
mini.get("tree1").loadList(mydata);
}
}
firstTreeLoad();
/*
上面结果数据如下:
{id: 101239, parentid_id: 0, FNAME: '研究院[2]', isLeaf: 0, expanded: 0, …}
{id: 101240, parentid_id: 0, FNAME: '物料申请单[4]', isLeaf: 0, expanded: 0, …}
{id: 101241, parentid_id: 0, FNAME: 'BOM[2]', isLeaf: 0, expanded: 0, …}
{id: 130201, parentid_id: 0, FNAME: '培训文档[5]', isLeaf: 0, expanded: 0, …}
{id: 130203, parentid_id: 0, FNAME: '产品文件[3]', isLeaf: 0, expanded: 0, …}
{id: 134274, parentid_id: 0, FNAME: '项目模板[1]', isLeaf: 0, expanded: 0, …}
{id: 134275, parentid_id: 0, FNAME: '公司项目[1]', isLeaf: 0, expanded: 0, …}
{id: 135009, parentid_id: 0, FNAME: '设计变更[2]', isLeaf: 0, expanded: 0, …}
*/
//lazytree
function onBeforeTreeLoad(e) {
// var tree = e.sender; //树控件
var node = e.node; //当前节点
// var params = e.params; //参数对象
//可以传递自定义的属性
// params.parameter = node.id; //后台:request对象获取"myField"
// var levelnode = tree.getAncestors(e.node);//获取该节点所有父节点
var jsonObj =
{
"parameter": node.id
}
//加载文件夹树
mydata = null;
fnWebApiClient(getFileForlderByParentForldId, jsonObj)
if (mydata != null && mydata.length > 0)
mini.get("tree1").loadNode(mydata);
}
/*
上面结果数据如下:
{id: 101242, parentid_id: 101239, FNAME: '设计图纸[2]', isLeaf: 0, expanded: 0, …}
{id: 101243, parentid_id: 101239, FNAME: '一般文档[2]', isLeaf: 0, expanded: 0, …}
{id: 101244, parentid_id: 101239, FNAME: 'BOM(结构设计部)[2]', isLeaf: 0, expanded: 0, …}
*/
</script>
</body>
</html>
复制代码
作者:
felt
时间:
2023-5-24 09:13:45
都是静态数据了,参考这些代码
<div class="mini-tree" id="tree1" style="width: 300px; height: 300px" virtualscroll="true" showCheckBox="true">
</div>
tree.loadData([{ id: 1, text: "a", isLeaf: false, asyncLoad: false}])
tree.on("beforeexpand", function (e) {
var cds = tree.getChildNodes(e.node);
if (cds.length < 1) {
var nodes = [];
for (var i = 1; i < 3001; i++) {
var node = { id: e.node.id + "_" + i, text: e.node.text + "_" + i, isLeaf: false, asyncLoad: false, expanded: false };
nodes.push(node);
}
tree.addNodeCls(e.node, "mini-tree-loading");
tree.addNodes(nodes, e.node);
}
})
复制代码
作者:
insony@qq.com
时间:
2023-5-24 11:43:45
felt 发表于 2023-5-24 09:13
都是静态数据了,参考这些代码
非常感谢,效果刚刚的
欢迎光临 jQuery MiniUI (http://miniui.com/discuss/)
Powered by Discuz! X2