Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/06/2011, 14:35
celineadiction
 
Fecha de Ingreso: octubre-2010
Mensajes: 93
Antigüedad: 14 años, 6 meses
Puntos: 0
ComboBox anidados

Hola amigos necesito que me ayuden a saber cual es mi error para cargar este combo:

aqui es donde creo la ventana
Código Javascript:
Ver original
  1. Ext.ns("com.quizzpot.tutorial");
  2.  
  3. com.quizzpot.tutorial.LinkedComboBoxTutorial = {
  4.     init: function(){
  5.         this.countryStore = this.getStore();
  6.         this.stateStore = this.getStore();
  7.         this.cityStore = this.getStore();
  8.        
  9.         this.countryCmb = new Ext.form.ComboBox({
  10.             store: this.countryStore,
  11.             id: 'country',
  12.             valueField: 'value',
  13.             displayField: 'label',
  14.             triggerAction: 'all',
  15.             emptyText: 'Select a Country',
  16.             fieldLabel: 'Country'
  17.         });
  18.        
  19.         this.stateCmb = new Ext.form.ComboBox({
  20.             store: this.stateStore,
  21.             disabled: true,
  22.             id: 'state',
  23.             valueField: 'value',
  24.             displayField: 'label',
  25.             triggerAction: 'all',
  26.             mode: 'local',
  27.             emptyText: 'Select a Contry first',
  28.             fieldLabel: 'State'
  29.         });
  30.    
  31.         this.cityCmb = new Ext.form.ComboBox({
  32.             store: this.countryStore,
  33.             disabled: true,
  34.             id : 'city',
  35.             valueField: 'value',
  36.             displayedField: 'label',
  37.             triggerAction: 'all',
  38.             //mode: 'local',
  39.             emptyText: 'Select a State first',
  40.             fieldLabel: 'City'
  41.         });
  42.        
  43.         this.window = new Ext.Window({
  44.             title: 'Linked ComboBox',
  45.             layout:'form',
  46.             width:300,
  47.             height:200,
  48.             bodyStyle: 'padding:5px;background-color:#fff',
  49.             items: [this.countryCmb,this.stateCmb,this.cityCmb]
  50.         });
  51.         this.window.show();
  52.        
  53.         this.countryCmb.on('select',function(cmb,record,index){
  54.             this.stateCmb.enable();
  55.             this.stateCmb.clearValue();
  56.             this.stateStore.load({params:{id:record.get('value')}});
  57.         },this);
  58.        
  59.         this.stateCmb.on('select',function(cmb,record,index){
  60.             this.cityCmb.enable();
  61.             this.cityCmb.clearValue();
  62.             this.cityStore.load({params:{id2:record.get('value')}})
  63.         },this);
  64.     },
  65.        
  66.     getStore: function(){
  67.         var store = new Ext.data.JsonStore({
  68.             url:'linked-cmb.php',
  69.             root:'data',
  70.             fields: ['value','label']
  71.         });
  72.         return store;
  73.     }
  74. }
  75.  
  76. Ext.onReady(com.quizzpot.tutorial.LinkedComboBoxTutorial.init,com.quizzpot.tutorial.LinkedComboBoxTutorial);

y este es el codigo php que me devuelve el valor que debe ir en los combos
Código PHP:
Ver original
  1. <?php
  2.  
  3. $countries = array('Argentina','España','México','Perú','United States');
  4.  
  5. $states = array(
  6.     array('Buenos Aires','Córdoba','Rosario','Mendoza','Santa Fe'),
  7.     array('Madrid','Valencia','Barcelona','Pamplona'),
  8.     array('Distrito Federal','Monterrey','Guadalajara'),
  9.     array('La Victoria','Piura','Surco','Lima'),
  10.     array('Texas','California','New york','Virginia')
  11. );
  12.  
  13. $cities = array(
  14.     array('ciudad 1', 'ciudad 2', 'ciudad 3'),
  15.     array('ciudad 4', 'ciudad 5', 'ciudad 6'),
  16.     array('ciudad 4', 'ciudad 5', 'ciudad 6'),
  17.     array('ciudad 4', 'ciudad 5', 'ciudad 6'),
  18.     array('ciudad 4', 'ciudad 5', 'ciudad 6')
  19. );
  20.  
  21. $id = $_REQUEST['id'];
  22. $idd=$_REQUEST['id2'];
  23.  
  24. if($id==""){
  25.     echo toJSON($countries);
  26. }
  27. if($id!=""){
  28.     echo toJSON($states[$id]);
  29. }
  30. if($idd!=""){
  31.     echo toJSON($cities[$idd]);
  32. }
  33.  
  34. function toJSON($array){
  35.     $data=array();
  36.     $i=0;
  37.     $total = count($array);
  38.     foreach($array as $key=>$value){
  39.         array_push($data,array(
  40.             'value'=>$i++,
  41.             'label'=>$value
  42.         ));
  43.     }
  44.    
  45.     return json_encode(array(
  46.         'total'=>$total,
  47.         'data'=>$data
  48.     ));
  49. }
  50. ?>

con eso solamente consigo que se carguen los primeros dos combos, y no se que hago mal que el tercero no carga....


muchas gracias de antemano

Última edición por celineadiction; 13/06/2011 a las 15:35