extjs 4:仅按特定id显示树面板节点 MySQL数据库: tree.php 问题:
1) 我只想显示树面板根,其中id为38和43。如果我们更改.php中的代码,当单击树面板时,树无法扩展数据。因此,我不这样认为,我们在php脚本中更改代码?如何仅在树面板中显示我想要的数据?extjs 4:仅按特定id显示树面板节点 MySQL数据库: tree.php 问题:,php,javascript,mysql,ajax,extjs4,Php,Javascript,Mysql,Ajax,Extjs4,1) 我只想显示树面板根,其中id为38和43。如果我们更改.php中的代码,当单击树面板时,树无法扩展数据。因此,我不这样认为,我们在php脚本中更改代码?如何仅在树面板中显示我想要的数据? P/S:id的传递参数是灵活的,不仅仅是38和43。我认为这将满足您的需要: <?php mysql_connect("localhost", "root", "") or die("Could not connect"); mysql_select_db("tree") or
P/S:id的传递参数是灵活的,不仅仅是38和43。
我认为这将满足您的需要:
<?php
mysql_connect("localhost", "root", "") or die("Could not connect");
mysql_select_db("tree") or die("Could not select database");
$parent_id = $_GET['node'];
$id = $_GET['id'];
// 1) Remove false as checked
$query = "SELECT id, text,parent_id, leaf FROM mytree WHERE parent_id='".$parent_id."' ";
if($parent_id == 0)
$query = $query."AND id IN (".$id.") ";
$query = $query."ORDER BY text ASC";
$rs = mysql_query($query);
$arr = array();
while($obj = mysql_fetch_object($rs)) {
// 2) If no leaf then destroy the attribute
if($obj->leaf != "false"){
// 1) set checked attribute with an boolean value
$obj->checked = false;
}
$arr[] = $obj;
}
echo json_encode($arr);
?>
不确定为什么C.Y.的编辑建议被拒绝,但我已经添加了它,因为它是正确的。
<?php
mysql_connect("localhost", "root", "") or die("Could not connect");
mysql_select_db("tree") or die("Could not select database");
$parent_id = $_GET['node'];
$id = $_GET['id'];
// 1) Remove false as checked
$query = "SELECT id, text,parent_id, leaf FROM mytree WHERE parent_id='".$parent_id."' ORDER BY text ASC";
$rs = mysql_query($query);
$arr = array();
while($obj = mysql_fetch_object($rs)) {
// 2) If no leaf then destroy the attribute
if($obj->leaf != "false"){
// 1) set checked attribute with an boolean value
$obj->checked = false;
}
$arr[] = $obj;
}
echo json_encode($arr);
?>
Ext.onReady(function() {
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'tree.php',
extraParams :{id:'38,43'},
// Here Magic comes
actionMethods: {
create : 'GET',
read : 'GET',
update : 'GET',
destroy: 'GET'
}
},
sorters: [{
property: 'leaf',
direction: 'ASC'
}, {
property: 'text',
direction: 'ASC'
}]
});
<?php
mysql_connect("localhost", "root", "") or die("Could not connect");
mysql_select_db("tree") or die("Could not select database");
$parent_id = $_GET['node'];
$id = $_GET['id'];
// 1) Remove false as checked
$query = "SELECT id, text,parent_id, leaf FROM mytree WHERE parent_id='".$parent_id."' ";
if($parent_id == 0)
$query = $query."AND id IN (".$id.") ";
$query = $query."ORDER BY text ASC";
$rs = mysql_query($query);
$arr = array();
while($obj = mysql_fetch_object($rs)) {
// 2) If no leaf then destroy the attribute
if($obj->leaf != "false"){
// 1) set checked attribute with an boolean value
$obj->checked = false;
}
$arr[] = $obj;
}
echo json_encode($arr);
?>