jQuery EasyUI 樹(shù)形菜單 – 創(chuàng)建異步樹(shù)形菜單

2022-06-08 16:29 更新

jQuery EasyUI 樹(shù)形菜單 - 創(chuàng)建異步樹(shù)形菜單

本節(jié)將介紹創(chuàng)建異步的jQuery EasyUI樹(shù)形菜單(Tree)。

為了創(chuàng)建異步的樹(shù)形菜單,每一個(gè)樹(shù)節(jié)點(diǎn)必須要有一個(gè)'id'屬性,這個(gè)將提交回服務(wù)器去檢索子節(jié)點(diǎn)數(shù)據(jù)。

創(chuàng)建樹(shù)形菜單(Tree)

	<ul id="tt" class="easyui-tree"  url="tree2_getdata.php">
	</ul>

服務(wù)器端代碼

	$id = isset($_POST['id']) ? intval($_POST['id']) : 0;

	include 'conn.php';

	$result = array();
	$rs = mysql_query("select * from nodes where parentId=$id");
	while($row = mysql_fetch_array($rs)){
		$node = array();
		$node['id'] = $row['id'];
		$node['text'] = $row['name'];
		$node['state'] = has_child($row['id']) ? 'closed' : 'open';
		array_push($result,$node);
	}

	echo json_encode($result);

	function has_child($id){
		$rs = mysql_query("select count(*) from nodes where parentId=$id");
		$row = mysql_fetch_array($rs);
		return $row[0] > 0 ? true : false;
	}

下載 jQuery EasyUI 實(shí)例

jeasyui-tree-tree2.zip

以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)