在后台管理系统开发的过程中,上左右的布局是最常见的页面布局方式,现在我们来看看使用easyui这个jquery前端框架如何快速搭建一个可用的页面框架。

1.在页面中引入easyui所需的文件

1 <%-- 加载easyui的样式文件,bootstrap风格 --%>
2 <link href="${ctx }/css/themes/bootstrap/easyui.css" rel="stylesheet">
3 <link href="${ctx }/css/themes/icon.css" rel="stylesheet">
4 <%-- 加载jquery和easyui的脚本文件 --%>
5 <script src="${ctx }/js/jquery-easyui-1.4.4/jquery.min.js"></script>
6 <script src="${ctx }/js/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
7 <script src="${ctx }/js/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>

2.在页面body部分构建必要的html结构

<body>
<div id="home-layout">
<!-- 页面北部,页面标题 -->
<div data-options="region:'north'" style="height:50px;">
<!-- add your code -->
</div>
<!-- 页面西部,菜单 -->
<div data-options="region:'west',title:'菜单栏'" style="width:200px;">
<div class="home-west">
<ul id="home-west-tree"></ul>
</div>
</div>
<!-- 页面中部,主要内容 -->
<div data-options="region:'center'">
<div id="home-tabs">
<div title="首页">
<h2 style="text-align: center">欢迎登录</h2>
</div>
</div>
</div>
</div>
</body>

这里需要注意一点:easyui在使用layout布局的时候,north、south需要指定高度,west、east需要指定宽度,而center会自动适应高和宽。

3.使用js初始化easyui组件

我个人比较推荐使用js代码去初始化easyui组件,而不使用easyui标签中的data-options属性去初始化。因为对于后台开发人员来说,写js代码可能比写html标签更加熟悉,而且这样使得html代码更加简洁。

<script>
$(function(){
/*
* 初始化layout
*/
$("#home-layout").layout({
//使layout自适应容器
fit: true
}); /*
* 获取左侧菜单树,并为其节点指定单击事件
*/
$("#home-west-tree").tree({
    //加载菜单的数据,必需
url: "${ctx }/pages/home-west-tree.json",
method: "get",
    //是否有层次线
lines: true,
    //菜单打开与关闭是否有动画效果
animate: true,
    //菜单点击事件
onClick: function(node){
if(node.attributes && node.attributes.url){
         //打开内容区的tab,代码在其后
addTab({
url: "${ctx }/" + node.attributes.url,
title: node.text
});
}
}
});   /*
* 初始化内容区的tabs
*/
$("#home-tabs").tabs({
fit : true,
    //tab页是否有边框
border : false
});
})
</script>
<script>
/*
* 在内容区添加一个tab
*/
function addTab(params){
var t = $("#home-tabs");
var url = params.url;
var opts = {
title: params.title,
closable: true,
href: url,
fit: true,
border: false
};
//如果被选中的节点对应的tab已经存在,则选中该tab并刷新内容
//否则打开一个新的tab
if(t.tabs("exists", opts.title)){
var tab = t.tabs("select", opts.title).tabs("getSelected");
t.tabs("update", {
tab: tab,
options: opts
});
}else{
t.tabs("add", opts);
}
}
</script>

4.easyui-tree组件所需的json格式

easyui使用的传输格式为json,它对json内容的格式有比较严格的限制,所以请注意查看api。

text为树的节点名称,children则表示子节点,state表示关闭的状态(我们可以利用这个属性来构建延迟加载树),而attributes则是easyui-tree为我们提供的一个自定义属性,在这个属性下,我们可以自定义属性,例如我就在其中定义了url属性,并为其赋值。当然,我们还能够为其添加其他自定义属性。

[{
"text":"区域管理",
"attributes":{
"url":"pages/consume/area/areaList.jsp"
}
},{
"text":"预约信息管理",
"children":[{
"text":"商户预约信息查询",
"attributes":{
"url":"/pages/consume/reservation/merchantReservation/merchantReservationList.jsp"
}
}]
},{
"text":"准入申请管理",
"children":[{
"text":"商户准入申请",
"state":"closed",
"children":[{
"text":"商户待处理申请",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_wait"
}
},{
"text":"商户审批中申请",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_current"
}
},{
"text":"商户审批通过申请",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_pass"
}
},{
"text":"商户被拒绝申请",
"attributes":{
"url":"waterAply.do?method=toList&channelType=1&handleFlag=aply_refuse"
}
}]
}]
},{
"text":"准入审批管理",
"children":[{
"text":"商户审批管理",
"state":"closed",
"children":[{
"text":"当前任务",
"children":[{
"text":"商户当前初审任务",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalTrial.jsp"
}
},{
"text":"商户当前复审任务",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalRetrial.jsp"
}
}]
},{
"text":"商户已完成任务",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalDone.jsp"
}
},{
"text":"商户不通过任务",
"attributes":{
"url":"pages/consume/approval/merchantApproval/merchantApprovalRefuse.jsp"
}
}]
}]
}]

就这样,我们使用easyui完成了简单的上左右布局。

最新文章

  1. 使用lnmp一键安装包后yum源出现的问题与解决
  2. zend studio 10.6 汉化破解
  3. OpenStack fuel-web不可用解决办法
  4. Activity(二)
  5. POJ 2676/2918 数独(dfs)
  6. 每天收获一点点------Hadoop基本介绍与安装配置
  7. [Contiki系列论文之1]Contiki——为微传感器网络而生的轻量级的、灵活的操作系统
  8. 在VB中动态执行VBS代码,可操控窗体控件
  9. mysql5.7基于gtid主从重做
  10. Visual studio 2015 Community 安装过程中遇到问题的终极解决
  11. SpringMVC中对多部件类型解析---文件(图片)上传
  12. des加密破解
  13. WinPE引导硬盘安装64位的Windows_Server_2008系统
  14. abstract抽象
  15. Objective-C编程 - 关于Block的要点
  16. 链表一元多项式计算器的实现(Java语言描述)
  17. class字节码结构(一)(字节码结构和字节常量池的结构)
  18. ubuntu环境下eclipse的安装以及hadoop插件的配置
  19. python 删除字典元素
  20. TabLayout 使用方法 (基础)

热门文章

  1. BUU八月份水题记录
  2. C语言运算符(关系运算符)+(逻辑运算符)
  3. 指向结构的指针 struct结构名称 *结构指针变量名
  4. 在游戏中播放cg视频遇到的问题
  5. 删除EFI系统分区(ESP)后Windows无法启动,重建引导分区并修复启动的过程
  6. MySQL 不完全入门指南
  7. Golang语言系列-16-context上下文
  8. CVE-2020-0796提权操作
  9. 页面模型 PageModel
  10. noip8