1. #1
    Ext User
    Join Date
    Sep 2007
    Location
    Porto / Portugal
    Posts
    93
    Vote Rating
    0
    pongz79 is on a distinguished road

      0  

    Default Help on updating the Tutorial:Linked Combos Tutorial for Ext 2 for JSON data

    Help on updating the Tutorial:Linked Combos Tutorial for Ext 2 for JSON data


    Hello.
    I'm having troubles doing and understanding how to update the Tutorial:Linked Combos Tutorial for Ext 2 to an example that uses JSON data.
    What i want to do is populate the first ComboBox (countries) with all the records from the database and then when we choose one country, populate the second ComboBox (cities) with the values that depends of the selected country.
    This is my try:
    lcombo.js
    PHP Code:
    // reference local blank image
    Ext.BLANK_IMAGE_URL '../ext-2.0-beta1/resources/images/default/s.gif';
     
    Ext.namespace('LCombo''LCombo.countries''LCombo.cities');
     
    LCombo.countries = [
         [
    'USA''United States of America'],
         [
    'D''Germany'],
         [
    'F''France'],
         [
    'GB''Great Britain']
    ];
     
    LCombo.cities = [
         [
    1'USA''New York'],
         [
    2'USA''Cleveland'],
         [
    3'USA''Austin'],
         [
    4'USA''Los Angeles'],
         [
    5'D''Berlin'],
         [
    6'D''Bonn'],
         [
    7'F''Paris'],
         [
    8'F''Nice'],
         [
    9'GB''London'],
         [
    10'GB''Glasgow'],
         [
    11'GB''Liverpool']
    ];
     
    // create application
    LCombo.app = function() {
        
    // do NOT access DOM from here; elements don't exist yet
     
        // private variables
     
        // private functions
     
        // public space
        
    return {
     
            
    // public methods
            
    init: function() {
                var 
    form = new Ext.FormPanel({
                     
    renderTodocument.body,
                     
    width400,
                     
    height300,
                     
    style'margin:16px',
                     
    bodyStyle'padding:10px',
                     
    title'Linked Combos',
                     
    defaults: {xtype:'combo'},
                     
    items:[{
                         
    fieldLabel'Select Country',
                         
    displayField'country',
                         
    valueField'cid',
                         
    store: new Ext.data.Store({
                             
    proxy: new Ext.data.HttpProxy({
                                 
    url'countries.php'
                             
    }),
                             
    reader: new Ext.data.JsonReader({
                                 
    totalProperty'total',
                                
    root'sample',
                                
    id'cid'
                             
    }, [
                                 {
    name'cid'},
                                {
    name'country'}
                             ])
                        }),
                        
    triggerAction'all',
                        
    mode'remote',
                        
    listeners: {select:{fn:function(combovalue) {
                            var 
    comboCity Ext.getCmp('combo-city');
                            
    comboCity.setValue('');
                            
    comboCity.store.load({params:{selectedValuecombo.getValue()}});
                            }}
                        }
     
                    },{
                         
    fieldLabel'Select City',
                         
    displayField'city',
                         
    valueField'id',
                         
    id'combo-city',
                         
    store: new Ext.data.Store({
                             
    proxy: new Ext.data.HttpProxy({
                                 
    url'cities.php'
                             
    }),
                             
    reader: new Ext.data.JsonReader({
                                 
    totalProperty'total',
                                
    root'sample',
                                
    id'cid'
                             
    }, [
                                 {
    name'id'},
                                {
    name'cid'},
                                {
    name'city'}
                             ])
                        }),
                        
    triggerAction'all',
                        
    mode'remote',
                        
    lastQuery''
                    
    }]
                });
            }
        };
    }(); 
    // end of app
     
    // end of file 
    countries.php:
    PHP Code:
    <?php
        $conn 
    mysql_connect("localhost""root""");
        if (!
    $conn)
        {
            die(
    'Could not connect: ' mysql_error());
        }
        
    mysql_select_db('linked_combos'$conn);
        
        
    $rs_count mysql_query("SELECT cid, country FROM countries");
        
    $rows mysql_num_rows($rs_count);
        
        
    $query "SELECT cid, country FROM countries";
        
    $rs mysql_query($query);
        
        while (
    $obj=mysql_fetch_object($rs)) {
            
    $arr[] = $obj;
        }
        
        echo 
    '{"total":' $rows ',"sample":'.json_encode($arr).'}';
    ?>
    cities.php
    PHP Code:
    <?php
        $conn 
    mysql_connect("localhost""root""");
        if (!
    $conn)
        {
            die(
    'Could not connect: ' mysql_error());
        }
        
    mysql_select_db('linked_combos'$conn);
        
        
    $rs_count mysql_query("SELECT id, cid, city FROM cities");
        
    $rows mysql_num_rows($rs_count);
        
        
    $query "SELECT id, cid, city FROM cities WHERE cities.cid='" $_POST['selectedValue'] . "'";
        
    $rs mysql_query($query);
        
        while (
    $obj=mysql_fetch_object($rs)) {
            
    $arr[] = $obj;
        }
        
        echo 
    '{"total":' $rows ',"sample":'.json_encode($arr).'}';
    ?>
    countries.php returned data:
    Code:
    {"total":4,"sample":[{"cid":"D","country":"Germany"},{"cid":"F","country":"France"},{"cid":"GB","country":"Great Britain"},{"cid":"USA","country":"United States of America"}]}
    cities.php returned data:
    Code:
    {"total":11,"sample":[{"id":"3","cid":"USA","city":"New York"},{"id":"4","cid":"USA","city":"Cleveland"},{"id":"5","cid":"USA","city":"Austin"},{"id":"6","cid":"USA","city":"LosAngeles"},{"id":"7","cid":"D","city":"Berlin"},{"id":"8","cid":"D","city":"Bonn"},{"id":"9","cid":"F","city":"Paris"},{"id":"10","cid":"F","city":"Nice"},{"id":"11","cid":"GB","city":"London"},{"id":"12","cid":"GB","city":"Glasgow"},{"id":"13","cid":"GB","city":"Liverpool"}]}
    The problem is that the second ComboBox does not get filtered.
    Any ideas???

    Best reguards

  2. #2
    Ext User
    Join Date
    Sep 2007
    Location
    Porto / Portugal
    Posts
    93
    Vote Rating
    0
    pongz79 is on a distinguished road

      0  

    Default


    I've been searching the forum and seems that i'm gettint into the right way.
    I'm using a listener function in the first ComboBox (countries) for reloading the second and the returned JSON data seems ok.
    Returned data after selecting country GB:
    Code:
    {"total":11,"sample":[{"id":"11","cid":"GB","city":"London"},{"id":"12","cid":"GB","city":"Glasgow"},{"id":"13","cid":"GB","city":"Liverpool"}]}
    The problem now is when i click the second ComboBox nothing appears in it.
    Any ideas/suggestions???

    Best reguards

    [EDIT]
    Changed the code for my actual one...
    [/EDIT]

  3. #3
    Ext User
    Join Date
    Sep 2007
    Location
    Porto / Portugal
    Posts
    93
    Vote Rating
    0
    pongz79 is on a distinguished road

      0  

    Default


    Anyone please...
    I'm really stuck here...
    Thanks

    Best reguards

  4. #4
    Ext User
    Join Date
    Aug 2007
    Posts
    96
    Vote Rating
    0
    vibez is on a distinguished road

      0  

    Default


    Hi,

    Did you ever find a solution to this?

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi