JQuery EasyUI(44)

                   第三十六章: Tree(数)组件【1】

学习要点:

  1. 加载方式
  2. 属性列表

 一、加载方式

1.class加载方式:

<!DOCTYPE html>
<html>
  <head>
    <title>JQuery Easy UI</title>
    <meta charset="utf-8"/>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>     
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>     
    <script type="text/javascript" src="js/index.js"></script> 
    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css"/>
    <style>
       .textbox{
            height:200px;
            margin:0;
            padding:0 2px;
            box-sizing:content-box;
       }
    </style>              
</head>
  <body>
   <ul class="easyui-tree">
      <li>
          <span>系统管理</span>
          <ul>
               <li>
                  <span>主机信息</span>
                  <ul>
                     <li>版本信息</li>
                     <li>数据库信息</li>
                  </ul>
               </li>
               <li>更新信息</li>
               <li>程序信息</li>
          </ul>
      </li>
      <li>
          <span>会员管理</span>
          <ul>
               <li>新增会员</li>
               <li>审核会员</li>
          </ul>
      </li>
   </ul>   
  </body>
</html>
树控件数据格式化:
id:节点ID,对加载远程数据很重要。
text:显示节点文本(必选)。
state:节点状态,'open'或'closed',默认'open',如果为'closed'的时候,将不自动展开该节点。
checked:表示该节点是否被选中。
attributes:被添加到节点的自定义属性。
children:一个节点数组声明了若干节点。

 

2.JS调用加载:

<!DOCTYPE html>
<html>
  <head>
    <title>JQuery Easy UI</title>
    <meta charset="utf-8"/>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>     
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>     
    <script type="text/javascript" src="js/index.js"></script> 
    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css"/>  
    <style>
        .textbox{
            height:200px;
            margin:0;
            padding:0 2px;
            box-sizing:content-box;
       }
    </style>           
</head>
  <body>
     <ul id="box"></ul>   
  </body>
</html>
$(function(){
    $('#box').tree({
       url:tree.json,
  });
});
//tree.json
[
  { 
   "id":1,
   "text":"系统管理",
   "iconCls":"icon-save",
   "children":[
        {
           "text":"主机信息", 
           "state":"closed",         
           "children":[
               {
                 "text":"版本信息",          
               },
               {
                 "text":"数据库信息",          
               }
                    ];                    
         },
        {
           "text":"更新信息",          
         },
        {
           "text":"程序信息",          
         }
            ];
   }
  {
   "id":2,
   "text":"会员管理",
   "children":[
        {
           "text":"新增会员",          
         },
        {
           "text":"审核会员",          
         }
            ];
   }
]

 

 二、属性列表

properGrid属性
属性名说明
urlstring检索远程数据的URL地址。
methodstring检索数据的HTTP方法。(POST/GET)
animateboolean定义节点在展开或折叠的时候是否显示动画效果。
checkboxboolean定义是否在每个节点之前都显示复选框。
cascadeCheckboolean定义是否层叠选中状态。
onlyleafCheakboolean定义是否只在未及节点之前显示复选框。
linesboolean定义是否显示树控件上的虚线。
dndboolean定义是否启用拖拽功能。
dataarray节点数据加载。
formatterfunction(onde)定义如何渲染节点的文本。
loaderfunction(param,success,error)定义如何从远程服务器中加载数据。返回false可以忽略本操作。该函数具备以下参数:param:发送到远程服务器的参数对象。success(data):当检索数据成功的时候调用的回调函数。error():当检索数据失败的时候调用的回调函数。
loaderFilterfunction(data,parent)返回过滤的数据进行展示。返回数据是标准树格式。该函数具备以下参数:data:加载的原始数据。param:DOM对象,代表父节点。
<!DOCTYPE html>
<html>
  <head>
    <title>JQuery Easy UI</title>
    <meta charset="utf-8"/>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>     
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>     
    <script type="text/javascript" src="js/index.js"></script> 
    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css"/>   
    <style>
        .textbox{
            height:200px;
            margin:0;
            padding:0 2px;
            box-sizing:content-box;
       }
    </style>           
</head>
  <body>
     <ul id="box"></ul>     
  </body>
</html>
$(function(){
    $('#box').tree({
       url:tree.json,
       animate:true,
       checkbox:true,
       cascadeCheck:true,
       onlyLeafCheck:true,
       lines:true,
       dnd:true,
       data:[{
         "text":"本地节点",
          }],

       formatter:function(node){
           console.log(node);
           return '[' + node.text + ']';
    },
  });
});
//tree.json
[
  { 
   "id":1,
   "text":"系统管理",
   "iconCls":"icon-save",
   "children":[
        {
           "text":"主机信息", 
           "state":"closed",         
           "children":[
               {
                 "text":"版本信息",          
               },
               {
                 "text":"数据库信息",          
               }
                    ];                    
         },
        {
           "text":"更新信息",          
         },
        {
           "text":"程序信息",          
         }
            ];
   }
  {
   "id":2,
   "text":"会员管理",
   "children":[
        {
           "text":"新增会员",          
         },
        {
           "text":"审核会员",          
         }
            ];
   }
]

 

作者:Roger_CoderLife

链接:https://blog.csdn.net/Roger_CoderLife/article/details/103763010

本文根据网易云课堂JQuery EasyUI视频教程翻译成文档,转载请注明原文出处,欢迎转载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值