国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

輕松學(xué)習(xí)jQuery插件EasyUI EasyUI實(shí)現(xiàn)樹形網(wǎng)絡(luò)基本操作(2)

2024-05-06 16:25:34
字體:
供稿:網(wǎng)友
這篇文章主要幫助大家輕松學(xué)習(xí)jQuery插件EasyUI,針對(duì)EasyUI實(shí)現(xiàn)樹形網(wǎng)絡(luò)基本操作,分為三大方面:動(dòng)態(tài)加載、添加分頁、以及惰性加載節(jié)點(diǎn),感興趣的小伙伴們可以參考一下
 

一、EasyUI樹形網(wǎng)格動(dòng)態(tài)加載
動(dòng)態(tài)加載樹形網(wǎng)格有助于從服務(wù)器上加載部分的行數(shù)據(jù),避免加載大型數(shù)據(jù)的長(zhǎng)時(shí)間等待。本教程將向您展示如何創(chuàng)建帶有動(dòng)態(tài)加載特性的樹形網(wǎng)格(TreeGrid)。

輕松學(xué)習(xí)jQuery插件EasyUI EasyUI實(shí)現(xiàn)樹形網(wǎng)絡(luò)基本操作(2)

創(chuàng)建樹形網(wǎng)格(TreeGrid)

 <table  url="treegrid3_getdata.php"  rownumbers="true"  idField="id" treeField="name"> <thead>  <tr>  <th field="name" width="250">Name</th>  <th field="quantity" width="100" align="right">Quantity</th>  <th field="price" width="150" align="right" formatter="formatDollar">Price</th>  <th field="total" width="150" align="right" formatter="formatDollar">Total</th>  </tr> </thead> </table>

服務(wù)器端代碼
treegrid3_getdata.php

$id = isset($_POST['id']) ? intval($_POST['id']) : 0; include 'conn.php';$result = array();$rs = mysql_query("select * from products where parentId=$id");while($row = mysql_fetch_array($rs)){ $row['state'] = has_child($row['id']) ? 'closed' : 'open'; $row['total'] = $row['price']*$row['quantity']; array_push($result, $row);} echo json_encode($result); function has_child($id){ $rs = mysql_query("select count(*) from products where parentId=$id"); $row = mysql_fetch_array($rs); return $row[0] > 0 ? true : false;}

二、EasyUI樹形網(wǎng)格添加分頁
第二部分教大家如何向帶有動(dòng)態(tài)加載特性的樹形網(wǎng)格(TreeGrid)添加分頁。

 輕松學(xué)習(xí)jQuery插件EasyUI EasyUI實(shí)現(xiàn)樹形網(wǎng)絡(luò)基本操作(2)

創(chuàng)建樹形網(wǎng)格(TreeGrid)

啟用樹形網(wǎng)格(TreeGrid)的分頁特性,必須添加 'pagination:true' 屬性,這樣頁面加載時(shí)就會(huì)向服務(wù)器發(fā)送 'page' 和 'rows' 參數(shù)。

 <table  data-options="  url: 'treegrid4_getdata.php',  rownumbers: true,  pagination: true,  pageSize: 2,  pageList: [2,10,20],  idField: 'id',  treeField: 'name',  onBeforeLoad: function(row,param){   if (!row) { // load top level rows   param.id = 0; // set id=0, indicate to load new page rows   }  }  "> <thead>  <tr>  <th field="name" width="250">Name</th>  <th field="quantity" width="100" align="right">Quantity</th>  <th field="price" width="150" align="right" formatter="formatDollar">Price</th>  <th field="total" width="150" align="right" formatter="formatDollar">Total</th>  </tr> </thead> </table>

服務(wù)器端代碼

treegrid4_getdata.php

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;$offset = ($page-1)*$rows; $id = isset($_POST['id']) ? intval($_POST['id']) : 0; include 'conn.php'; $result = array();if ($id == 0){ $rs = mysql_query("select count(*) from products where parentId=0"); $row = mysql_fetch_row($rs); $result["total"] = $row[0];  $rs = mysql_query("select * from products where parentId=0 limit $offset,$rows"); $items = array(); while($row = mysql_fetch_array($rs)){ $row['state'] = has_child($row['id']) ? 'closed' : 'open'; array_push($items, $row); } $result["rows"] = $items;} else { $rs = mysql_query("select * from products where parentId=$id"); while($row = mysql_fetch_array($rs)){ $row['state'] = has_child($row['id']) ? 'closed' : 'open'; $row['total'] = $row['price']*$row['quantity']; array_push($result, $row); }} echo json_encode($result); function has_child($id){ $rs = mysql_query("select count(*) from products where parentId=$id"); $row = mysql_fetch_array($rs); return $row[0] > 0 ? true : false;}

發(fā)送到服務(wù)器的參數(shù)包括:
page:要加載的當(dāng)前頁面。
rows:頁面尺寸大小。
id:父行的 id 值,從服務(wù)器返回的行將被添加。
當(dāng)展開一個(gè)行節(jié)點(diǎn)時(shí),'id' 值是大于 0 的。 當(dāng)改變頁碼時(shí),'id' 值應(yīng)該被設(shè)置為 0 來放置加載子行。
三、EasyUI樹形網(wǎng)格惰性加載節(jié)點(diǎn)
有時(shí)我們已經(jīng)得到充分的分層樹形網(wǎng)格(TreeGrid)的數(shù)據(jù)。 我們還想讓樹形網(wǎng)格(TreeGrid)按層次惰性加載節(jié)點(diǎn)。 首先,只加載頂層節(jié)點(diǎn)。 然后點(diǎn)擊節(jié)點(diǎn)的展開圖標(biāo)來加載它的子節(jié)點(diǎn)。 本教程展示如何創(chuàng)建帶有惰性加載特性的樹形網(wǎng)格(TreeGrid)。

 輕松學(xué)習(xí)jQuery插件EasyUI EasyUI實(shí)現(xiàn)樹形網(wǎng)絡(luò)基本操作(2)

創(chuàng)建樹形網(wǎng)格(TreeGrid)

 <table id="test"  data-options="  url: 'data/treegrid_data.json',  method: 'get',  rownumbers: true,  idField: 'id',  treeField: 'name',  loadFilter: myLoadFilter  "> <thead>  <tr>  <th field="name" width="220">Name</th>  <th field="size" width="100" align="right">Size</th>  <th field="date" width="150">Modified Date</th>  </tr> </thead> </table>

為了放置加載子節(jié)點(diǎn),我們需要為每個(gè)節(jié)點(diǎn)重命名 'children' 屬性。 正如下面的代碼所示,'children' 屬性重命名為 'children1'。 當(dāng)展開一個(gè)節(jié)點(diǎn)時(shí),我們調(diào)用 'append' 方法來加載它的子節(jié)點(diǎn)數(shù)據(jù)。
'loadFilter' 代碼

 function myLoadFilter(data,parentId){ function setData(){  var todo = [];  for(var i=0; i<data.length; i++){  todo.push(data[i]);  }  while(todo.length){  var node = todo.shift();  if (node.children){   node.state = 'closed';   node.children1 = node.children;   node.children = undefined;   todo = todo.concat(node.children1);  }  } }  setData(data); var tg = $(this); var opts = tg.treegrid('options'); opts.onBeforeExpand = function(row){  if (row.children1){  tg.treegrid('append',{   parent: row[opts.idField],   data: row.children1  });  row.children1 = undefined;  tg.treegrid('expand', row[opts.idField]);  }  return row.children1 == undefined; }; return data; }

以上就是針對(duì)樹形網(wǎng)絡(luò)的相關(guān)操作,希望對(duì)大家的學(xué)習(xí)有所幫助,大家可以結(jié)合前一篇文章進(jìn)行學(xué)習(xí),會(huì)有意想不到的收獲。



注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JavaScript/Ajax教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 巴里| 龙江县| 青州市| 新源县| 读书| 横峰县| 大埔区| 揭东县| 东平县| 寻乌县| 酉阳| 金川县| 常山县| 黄平县| 越西县| 佳木斯市| 海口市| 酒泉市| 固阳县| 灵宝市| 西宁市| 汉沽区| 兴仁县| 六安市| 房山区| 阿勒泰市| 博客| 那坡县| 安庆市| 昭苏县| 柳河县| 西丰县| 奎屯市| 青龙| 上犹县| 荔浦县| 邵阳市| 蓬溪县| 贵州省| 贞丰县| 长治市|