dtz33344 2013-02-12 09:16
浏览 51
已采纳

extjs 4:仅按特定ID显示树面板节点

MySQL DATABASE:

CREATE DATABASE `tree`;

DROP TABLE IF EXISTS `mytree`;
CREATE TABLE `mytree` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'node_id',
  `text` varchar(20) NOT NULL COMMENT 'node_name',
  `parent_id` int(11) NOT NULL,
  `leaf` varchar(5) NOT NULL COMMENT 'true/false',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=95 DEFAULT CHARSET=latin1;

INSERT INTO `mytree` VALUES (36,'Folder 1',0,'false'),
(38,'Folder 2',0,'false'),(42,'Text 1',36,'true'),
(43,'Folder 3',0,'false'),(44,'Text 2',36,'true'),
(52,'Text 6',38,'true'),(57,'Text 5',38,'true'),
(58,'Text 4',38,'true'),(73,'Subfolder 1',36,'false'),
(74,'Text 7',73,'true'),(75,'Text 10',73,'true'),
(76,'Text 9',73,'true'); 

tree.php

<?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);
?>

script:

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'
        }]
    });

Question:

1)i just want to show the tree panel root where id 38 and 43 only.if we changing the code inside .php , when clicked the tree panel the tree are cannot expand the data.so,i dont think so we changing the code in php script?how to just display the data i want in the tree panel? P/S:passing parameters of id are flexible, not only 38 and 43.

  • 写回答

1条回答 默认 最新

  • duanlu2935 2013-02-18 19:32
    关注

    I think this will work for what you want:

       <?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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)