Foros del Web » Programando para Internet » Javascript »

ComboBox anidados

Estas en el tema de ComboBox anidados en el foro de Javascript en Foros del Web. Hola amigos necesito que me ayuden a saber cual es mi error para cargar este combo: aqui es donde creo la ventana @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código ...
  #1 (permalink)  
Antiguo 13/06/2011, 14:35
 
Fecha de Ingreso: octubre-2010
Mensajes: 93
Antigüedad: 13 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
  #2 (permalink)  
Antiguo 14/06/2011, 15:51
 
Fecha de Ingreso: octubre-2010
Mensajes: 93
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: ComboBox anidados

alguien?? porfavor?? =)
  #3 (permalink)  
Antiguo 16/06/2011, 08:28
 
Fecha de Ingreso: octubre-2010
Mensajes: 93
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: ComboBox anidados

Lo he modificado de esta manera, pero me sigue dando problemas al cargar el tercer combo

Código Javascript:
Ver original
  1. Ext.ns("combos");
  2.  
  3. combos.ComboBox = {
  4.     init: function(){
  5.         this.countryStore = this.getStore();
  6.         this.stateStore = this.getStore();
  7.         this.cityStore = this.getStore();
  8.         this.coloniaStore = this.getStore();
  9.        
  10.         this.countryCmb = new Ext.form.ComboBox({
  11.             store: this.countryStore,
  12.             itemId: 'country',
  13.             id: 'country',
  14.             valueField: 'value',
  15.             loadingText:'',
  16.             displayField: 'label',
  17.             triggerAction: 'all',
  18.             emptyText: 'Seleccione Pais',
  19.             fieldLabel: 'Country'
  20.         });
  21.        
  22.         this.stateCmb = new Ext.form.ComboBox({
  23.             store: this.stateStore,
  24.             disabled: true,
  25.             id: 'state',
  26.             valueField: 'value',
  27.             loadingText:'',
  28.             displayField: 'label',
  29.             triggerAction: 'all',
  30.             mode: 'local',
  31.             emptyText: 'Primero seleccione un Pais',
  32.             fieldLabel: 'State'
  33.         });
  34.    
  35.         this.cityCmb = new Ext.form.ComboBox({
  36.             store: this.cityStore,
  37.             disabled: true,
  38.             id : 'city',
  39.             valueField: 'value',
  40.             loadingText:'',
  41.             displayedField: 'label',
  42.             triggerAction: 'all',
  43.             mode: 'local',
  44.             emptyText: 'Primero Seleccione un estado',
  45.             fieldLabel: 'Ciudad'
  46.         });
  47.        
  48.         this.coloniaCmb = new Ext.form.ComboBox({
  49.             store: this.coloniaStore,
  50.             disabled: true,
  51.             id: 'colonia',
  52.             valueField: 'value',
  53.             loadingText: '',
  54.             displayedField: 'label',
  55.             triggerAction: 'all',
  56.             mode: 'local',
  57.             emptyText: 'Primero Seleccione una ciudad',
  58.             fieldLabel: 'Colonia'
  59.         });
  60.    
  61.         this.window = new Ext.Window({
  62.             title: 'Combos Anidados',
  63.             layout:'form',
  64.             width:300,
  65.             height:160,
  66.             bodyStyle: 'padding:5px;background-color:#fff',
  67.             items: [this.countryCmb,this.stateCmb,this.cityCmb,this.coloniaCmb]
  68.         });
  69.         this.window.show();
  70.        
  71.         this.countryCmb.on('select',function(cmb,record,index){
  72.             this.stateCmb.enable();
  73.             this.stateCmb.clearValue();
  74.             this.stateStore.load({
  75.                 params:{
  76.                     id:record.get('value')
  77.                 }
  78.             });
  79.         },this);
  80.    
  81.         this.stateCmb.on('select',function(cmb,record,index){
  82.             this.cityCmb.enable();
  83.             this.cityCmb.clearValue();
  84.             this.cityStore.load({
  85.                 params:{
  86.                     id2:record.get('value')
  87.                 }
  88.             });
  89.         },this);
  90.        
  91.         this.cityCmb.on('select',function(cmb,record,index){
  92.             this.coloniaCmb.enable();
  93.             this.coloniaCmb.clearValue();
  94.             this.coloniaStore.load({
  95.                 params:{
  96.                     id3:record.get('value')
  97.                 }
  98.             });
  99.         },this);
  100.     },
  101.        
  102.     getStore: function(){
  103.         var store = new Ext.data.JsonStore({
  104.             url:'linked-cmb.php',
  105.             root:'data',
  106.             fields: ['value','label']
  107.         });
  108.         return store;
  109.     }
  110. }//fin de la clase
  111.  
  112. Ext.onReady(combos.ComboBox.init,combos.ComboBox);

y el codigo en php es este
Código PHP:
Ver original
  1. <?php
  2. include('../conexion.php');
  3.  
  4. if($_POST['id']=="" AND $_POST['id2']==""){
  5.     $query_busqueda = "SELECT * FROM select_0 ORDER BY id ASC";
  6.     $busqueda = mysql_query($query_busqueda) or die(mysql_error());
  7.    
  8.     $arre = array();
  9.     while ($row_busqueda = mysql_fetch_assoc($busqueda)){
  10.           $arre[] = $row_busqueda[opcion];
  11.     }
  12.     echo toJSON($arre);
  13. }
  14.  
  15. if($_POST['id']!=""){
  16.     $query_busqueda_estados = "SELECT * FROM select_1 WHERE domn_relacion='$_POST[id]' ORDER BY id ASC";
  17.     $busqueda_estados = mysql_query($query_busqueda_estados) or die(mysql_error());
  18.    
  19.     $ar[] = array();
  20.     while ($row_busqueda_estados = mysql_fetch_assoc($busqueda_estados)){
  21.           $ar[] = $row_busqueda_estados[opcion];
  22.     }
  23.     echo toJSON($ar);
  24. }
  25.  
  26.     if($_POST['id2']!=""){
  27.         $query_busqueda_ciudades = "SELECT * FROM select_2 WHERE relacion='$_POST[id2]' ORDER BY id ASC";
  28.         $busqueda_ciudades = mysql_query($query_busqueda_ciudades) or die(mysql_error());
  29.        
  30.         $arreglo_ciudades[] = array();
  31.         while($row_busqueda_ciudades = mysql_fetch_assoc($busqueda_ciudades)){
  32.             $arreglo_ciudades[] = $row_busqueda_ciudades[opcion];
  33.         }
  34.         echo "idc".$_POST[idc];
  35.         echo toJSON($arreglo_ciudades);
  36.     }
  37.    
  38.     if($_POST['id3']!=""){
  39.         $query_busqueda_colonia = "SELECT * FROM select_3 WHERE relacion='$_POST[id3]' ORDER BY id ASC";
  40.         $busqueda_colonia = mysql_query($query_busqueda_colonia) or die(mysql_error());
  41.        
  42.         $arreglo_colonias[] = array();
  43.         while($row_busqueda_colonias = mysql_fetch_assoc($busqueda_colonia)){
  44.             $arreglo_colonias [] = $row_busqueda_colonias[opcion];
  45.         }
  46.        
  47.         echo toJSON($arreglo_colonias);
  48.     }
  49.  
  50.     function toJSON($array){
  51.         $data=array();
  52.         $i=1;
  53.         $total = count($array);
  54.         foreach($array as $key=>$value){
  55.             array_push($data,array(
  56.                 'value'=>$i++,
  57.                 'label'=>$value
  58.             ));
  59.         }
  60.        
  61.         return json_encode(array(
  62.             'total'=>$total,
  63.             'data'=>$data
  64.         ));
  65.     }
  66. ?>

lo que pasa es que en codigo php está bien, pero a la hora de mandarlo al combo, aunque lo hago de la misma manera que con los dos anteriores, no se despliega nada =/

les agradecería bastante su ayuda =)

Última edición por celineadiction; 16/06/2011 a las 08:40
  #4 (permalink)  
Antiguo 16/06/2011, 12:02
 
Fecha de Ingreso: octubre-2010
Mensajes: 93
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: ComboBox anidados

problema resuelto... era por la propiedad 'displayField'

Etiquetas: celineadiction, combobox, javascript+php
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:20.