如何使用jQuery EasyUI设计组合树
EasyUI是一个HTML5框架,用于使用基于jQuery、React、Angular和Vue技术的用户界面组件。它有助于为交互式网络和移动应用程序构建功能,为开发者节省大量时间。
combotree是一个UI组件,它是下拉树与选择控件的结合。
EasyUI for jQuery的下载:
https://www.jeasyui.com/download/index.php
注意:在执行以下代码时,请注意预编译文件的正确文件路径。
示例1:下面的例子演示了使用文件 “dataTree.json “和jQuery EasyUI库的基本组合树。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0,
maximum-scale=1.0, user-scalable=no">
<!-- EasyUI specific stylesheets-->
<link rel="stylesheet" type="text/css"
href="themes/metro/easyui.css">
<link rel="stylesheet" type="text/css"
href="themes/mobile.css">
<link rel="stylesheet" type="text/css"
href="themes/icon.css">
<!--jQuery library -->
<script type="text/javascript"
src="jquery.min.js">
</script>
<!--jQuery libraries of EasyUI -->
<script type="text/javascript"
src="jquery.easyui.min.js">
</script>
</head>
<body>
<h2>jQuery EasyUI ComboTree</h2>
<p>
Click the button to show
the data tree.
</p>
<div style="margin: 20px 0"></div>
<!-- easyui-panel class is used -->
<div class="easyui-panel" style=
"width: 100%; max-width: 400px;
padding: 30px 60px;">
<div style="margin-bottom: 20px">
<!--easyui-combotree class is used-->
<input class="easyui-combotree"
value="131" data-options=
"url: 'dataTree.json',
method: 'get',
label: 'Select Node:',
labelPosition: 'top'"
style="width:100%">
</div>
</div>
</body>
</html>
dataTree.json:以下是文件 “dataTree.json “的代码,该文件在所有的例子中都用于数据。
[{
"id":1,
"text":"Users",
"children":[{
"id":11,
"text":"Photos",
"state":"closed",
"children":[{
"id":101,
"text":"Family"
},{
"id":102,
"text":"Colleagues"
},{
"id":103,
"text":"Relatives"
}]
},{
"id":12,
"text":"Program Files",
"children":[{
"id":131,
"text":"Intel"
},{
"id":132,
"text":"nodejs",
"attributes":{
"p1":"my Attribute1",
"p2":"my Attribute2"
}
},{
"id":133,
"text":"Common files"
},{
"id":134,
"text":"Mail",
"checked":true
}]
},{
"id":13,
"text":"home.html"
},{
"id":14,
"text":"tutorials.html"
},{
"id":15,
"text":"jobs.html"
}]
}]
输出:
- 具有初始化值的ComboTree:
- Basic ComboTree:
例子2:下面的代码演示了对组合树进行的基本方法。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0,
maximum-scale=1.0, user-scalable=no">
<!-- EasyUI specific stylesheets-->
<link rel="stylesheet" type="text/css"
href="themes/metro/easyui.css">
<link rel="stylesheet" type="text/css"
href="themes/mobile.css">
<link rel="stylesheet" type="text/css"
href="themes/icon.css">
<!--jQuery library -->
<script type="text/javascript"
src="jquery.min.js">
</script>
<!--jQuery libraries of EasyUI -->
<script type="text/javascript"
src="jquery.easyui.min.js">
</script>
</head>
<body>
<h2>jQuery EasyUI ComboTree </h2>
<p>Click the buttons </p>
<div class="easyui-panel" style=
"width: 100%; max-width: 400px;
padding: 30px 60px;">
<div style="margin-bottom: 20px">
<input id="combotreeID"
class="easyui-combotree"
data-options="url: 'dataTree.json',
method: 'get',
label: 'Select folder/file:',
labelPosition: 'top'"
style="width:100%">
</div>
</div>
<div style="height:10px"></div>
<div id="resultDivID"></div>
<div style="margin:20px 0">
<!-- easyui-linkbutton class
is used to link -->
<a href="javascript:void(0)"
class="easyui-linkbutton"
onclick="getValue()">
GetValue
</a>
<a href="javascript:void(0)"
class="easyui-linkbutton"
onclick="setValue()">
SetValue
</a>
<a href="javascript:void(0)"
class="easyui-linkbutton"
onclick="disable()">
Disable
</a>
<a href="javascript:void(0)"
class="easyui-linkbutton"
onclick="enable()">
Enable
</a>
</div>
<script type="text/javascript">
/* Method to get value */
function getValue() {
var val = ('#combotreeID')
.combotree('getValue');
('#resultDivID')
.html(val + " is set");
}
/* Method to set value */
function setValue() {
('#combotreeID')
.combotree('setValue', '103');
}
/* Method to disable select button */
function disable() {
('#combotreeID')
.combotree('disable');
}
/* Method to enable select button */
function enable() {
$('#combotreeID')
.combotree('enable');
}
</script>
</body>
</html>
**输出:
- Before execution:
- After execution: