1

我有一个树面板,当我想显示它时我会加载孩子。

架构

  • 根(id:根)

    • 一个(编号:A)

      • 阿尔丰斯 (id: 8)

我想在我的 php 文件中获取 id。

对于 root childen (id: root) 可以,但对于最后一个就不行了。

商店发送的 URL 以获取根目录:

/ModuleGestion/php/Personne.php?action=read&_dc=1370835891009&node=root

商店发送的网址以获取最后一个:

/ModuleGestion/php/Personne.php?action=read&_dc=1370835898330

我的商店:

Ext.define('ModuleGestion.store.TreePersonne', {
    extend: 'Ext.data.TreeStore',

    requires: [
        'ModuleGestion.model.Personne'
    ],

    constructor: function (cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: true,
            model: 'ModuleGestion.model.Personne',
            storeId: 'StoreTreePersonne',
            root: {
                expanded: false,
                text: 'Personnes',
                id: 'root'
            },
            proxy: {
                type: 'ajax',
                node: 'id',
                api: {
                    create: 'http://localhost/ModuleGestion/php/Personne.php?action=create',
                    read: 'http://localhost/ModuleGestion/php/Personne.php?action=read',
                    update: 'http://localhost/ModuleGestion/php/Personne.php?action=update',
                    destroy: 'http://localhost/ModuleGestion/php/Personne.php?action=destroy'
                },
                reader: {
                    type: 'json',
                    root: 'data'
                }
            }
        }, cfg)]);
    }
});

我的模型:

Ext.define('ModuleGestion.model.Personne', {
    extend: 'Ext.data.Model',

    idProperty: 'idPersonne',

    fields: [{
        name: 'idPersonne'
    }, {
        name: 'MembreActif'
    }, {
        name: 'Actif'
    }, {
        name: 'idLienParente'
    }, {
        name: 'idAdresseResidence'
    }, {
        name: 'idAdressePostale'
    }, {
        name: 'idIdentite'
    }, {
        name: 'IdProprieteNumerique'
    }, {
        name: 'Nom'
    }, {
        name: 'NomJeuneFille'
    }, {
        name: 'Prenoms'
    }, {
        name: 'text'
    }, {
        name: 'id'
    }]
});

我的树面板:

items: [{
    xtype: 'treepanel',
    store: 'TreePersonne',
}]

我的 PHP 文件

<?php

require('includes/globals.php');

$fp = fopen('Erreurs.log', 'a');
fwrite($fp, $_SERVER['REQUEST_URI']);
fclose($fp);

$node = $_GET['node'];

$lettres = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

if ($node == 'root') {

    $row = Array();

    foreach ($lettres AS $lettre) {

        $rows[] = Array(
            "id" => $lettre,
            "text" => $lettre,
            "expanded" => "false",
            "leaf" => "false"
        );

    }

    $resultat = array(
        'success' => true,
        'data' => $rows
    );

} elseif (in_array($node, $lettres)) {

    $query = 'SELECT p.IdPersonne AS id, p.*, i.Nom, i.Prenoms, i.NomJeuneFille, CONCAT_WS(" ", i.Nom, i.NomJeuneFille, i.Prenoms) AS text FROM Personne AS p, Identite AS i WHERE i.Nom LIKE "' . $node . '%" AND p.Actif = 1 AND p.IdIdentite = i.IdIdentite';

    $resultat = $mysqli->query($query);

    $rows = array();

    while ($row = $resultat->fetch_assoc()) {
        $rows[] = array_merge($row, Array(
            "expanded" => "false",
            "leaf" => "false"
        ));
    }

    $resultat = array(
        'success' => true,
        'data' => $rows
    );

} else {

    $query = 'SELECT p.IdPersonne AS id, p.*, i.Nom, i.Prenoms, i.NomJeuneFille, CONCAT_WS(" ", i.Nom, i.NomJeuneFille, i.Prenoms) AS text FROM Personne AS p, Identite AS i WHERE p.Actif = 1 AND p.IdIdentite = i.IdIdentite';


    $resultat = $mysqli->query($query);

    if ($resultat) {

        $rows_mysql = array();

        while ($row = $resultat->fetch_assoc()) {
            $rows_mysql[] = $row;
        }

        $rows = Array();

        $lettre_active = null;
        $lettre_parent = Array();


        foreach ($rows_mysql AS $row) {

            $lettre_mysql = strtoupper(substr($row['text'], 0, 1));



            if ($lettre_active != $lettre_mysql) {


                if (count($lettre_data['data']) > 0) {
                    $rows[] = $lettre_data;

                }
                $lettre_data   = Array(
                    'id' => $lettre_mysql,
                    'text' => $lettre_mysql,
                    'expanded' => 'false',
                    'leaf' => 'false',
                    'data' => null
                );
                $lettre_active = $lettre_mysql;
            }

            $leaf                  = Array(
                'leaf' => 'true'
            );
            $lettre_data['data'][] = array_merge($row, $leaf);

        }

        $rows[] = $lettre_data;


    }

}

if ($rows) {
    $resultat = array(
        'success' => true,
        'data' => $rows
    );
} else {
    $resultat = array(
        'success' => false,
        'message' => $mysqli->error
    );
}




$json = json_encode($resultat);

if ($resultat['success'] == false) {
    $fp = fopen('Erreurs.log', 'a');
    fwrite($fp, date("Y-m-d H:i:s") . ' : ' . $_SERVER['SCRIPT_FILENAME'] . ' : ' . $resultat['message'] . "\n");
    fclose($fp);
}

$json = str_replace('"false"', 'false', $json);
$json = str_replace('"true"', 'true', $json);

echo ($json);

?>

解决方案是向商店添加一个绑定事件,如下所示:

beforeload: function(store, operation, eOpts) {
        operation.params.node = operation.node.get("id");
    }
4

0 回答 0