データベース内の私のデータ
現在、私のphpファイルは次のようなデータベースからデータを読み取っています
$data = array();
$sql = "SELECT * FROM tree";
$q = mysql_query($sql);
while ($r = mysql_fetch_array($q)) {
// check if have a child node
$qq = mysql_query("SELECT `id`, `text` FROM `tree` WHERE parent_id = '". $r['id'] ."'");
if (mysql_num_rows($qq) > 0) {
// if have a child
$r['leaf'] = false;
$r['cls'] = 'folder';
} else {
// if have no child
$r['leaf'] = true;
$r['cls'] = 'file';
}
$data[] = $r;
}
echo json_encode($data);
?>
<div id="tree_el"></div>
私のJavaScriptは
Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
]);
Ext.onReady(function() {
Ext.QuickTips.init();
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'treegetdata.php'
},
root: {
text: 'Eatables',
id: 'root_node',
expanded: true
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
var tree = Ext.create('Ext.tree.Panel', {
store: store,
renderTo: 'tree_el',
height: 300,
width: 250,
title: 'Eatables'
});
});
私の現在の結果は次のようになります
私の期待される結果は
データベースからデータを取得しているときに問題が発生しました。期待される形式が達成されるように修正してください。私のphpファイルには修正が必要だと思います。