0

我的观点 ProvaincePanel.js

Ext.define('MyApp.view.ProvaincePanel', {
    extend: 'Ext.dataview.NestedList',
    alias : 'widget.provaincePanel',

    config: {
     store : 'Provainces',
     title: 'Select your Provaince',
        displayField: 'text',

     detailCard: {
            html: 'You can see detail information here!'
        } 

    } 
});

我的商店 Provainces.js

Ext.define('MyApp.store.Provainces', {
    extend: 'Ext.data.TreeStore',

    config: {
        model: 'MyApp.model.Provaince',
        proxy: {
            type: 'ajax',
            url: 'http://127.0.0.1/pbesse-test/list-provainces3.php',
        }
    }    

});

我的模型 Provaince.js

Ext.define('MyApp.model.Provaince', {
    extend: 'Ext.data.Model',
    config: {
        fields: [{
            name: 'text',
            type: 'string'
        }]
    }
});

我的控制器 TheWorld.js

Ext.define('MyApp.controller.TheWorld', {
    extend : 'Ext.app.Controller',

    config: {
        profile: Ext.os.deviceType.toLowerCase(),
        stores : ['Provainces'],
        models : ['Provaince'],
        refs: {
            myContainer: 'provaincePanel'
        },
        control: {
            'provaincePanel': {
                activate: 'onActivate',
                leafitemtap: 'onDetailDisplay'
            }
        }   
    },

    onActivate: function() {
        console.log('Main container is active');
    },

    onDetailDisplay: function(nestedList, list, index, target, record) {
        var detailCard = nestedList.getDetailCard();
        detailCard.setHtml('Here is the detail information for ' + 
        record.get('text'));
    },

    onItemTap: function(view, list, index, target, record, event) {
        console.log('Item was tapped on the Data View');

        console.log(view, list, index, target, record, event);
        if(event.target.type == "button"){
            Ext.Msg.alert('You clicked on the Button ...', 
            'The country code selected is: ' + event.target.name);
        }
        else {
            Ext.Msg.alert('You clicked on the Row ...', 
            'The country code selected is: ' + record.get('code'));
        }
        //return false;
    },

    init: function() {
        console.log('Controller initialized');
    },    
});

list-provainces3.php 文件包含

<?php

    @mysql_connect('127.0.0.1','root','') or die(mysql_error());
    @mysql_select_db('pbesse_test');
    $node = $_GET['node'];

    $node = explode('%2F', $node);

    if(count($node) == 1) 
    {
        $sql = "SELECT * FROM provainces";

        $req = mysql_query($sql) or die(mysql_error());

        $data = array();

        while($res = mysql_fetch_array($req)){
            $tmp = array();
            $tmp['id'] = "root/".$res['id'];
            $tmp['text'] = utf8_encode($res['libelle']);
            $tmp['leaf'] = false;
            $tmp['cls'] = 'folder';
            $data[] = $tmp;
        }
    }
    if(count($node) == 2){
        $sql = "SELECT * FROM chateaux where id_provaince = ". $node[1];

        $req = mysql_query($sql) or die(mysql_error());

        $data = array();

        while($res = mysql_fetch_array($req)){
            $tmp = array();
            $tmp['id'] = "root/".$res['id_provaince']."/".$res['title'];
            $tmp['text'] = utf8_encode($res['libelle']);
            $tmp['leaf'] = false;
            $tmp['cls'] = 'folder';
            $data[] = $tmp;
        }
    }
    header('Content-Type: application/json, charset=UTF-8');
    echo str_replace('\\','' , json_encode($data));

    exit;
?>

当我执行应用程序时,我有一个国家列表,但是当我点击一个国家名称时,它会显示一条加载消息和应用程序错误

4

0 回答 0