Comunidad de diseño web y desarrollo en internet online

ComboBox+XML

Citar            
MensajeEscrito el 19 Oct 2005 07:21 pm
Tengo un XML que contiene varios modelos de automoviles, es algo asi

Código :

<vehiculo fabricante='Chevrolet' modelo='Astra' />   
<vehiculo modelo='Audi A4' fabricante='Audi' />
<vehiculo modelo='Peugeot 206 3P' fabricante='Peugeot' />
<vehiculo modelo='Peugeot 206 5P' fabricante='Peugeot' />
<vehiculo modelo='Peugeot 307' fabricante='Peugeot' />

Yo lo que quiero hacer es que llene el ComboBox con los fabricantes. El problema me aparece (no al cargar los datos, ya que gracias al tutorial de CL pude hacerlo) cuando quiero agregar a los fabricantes y que estos no se repitan ¿Habra alguna manera? Gracias por molestarse en leer

Por jon4

10 de clabLevel



 

_root.bsas_mc.casa_mc

msie
Citar            
MensajeEscrito el 19 Oct 2005 07:42 pm
Con una condicion antes de añadir algo al array, haces una busqueda en el array que estas llenando con el nodo del XML que estas leyendo, si esta no lo agregas en caso contrario lo agregas.



saludos :)

Por Maikel

BOFH

5575 de clabLevel

22 tutoriales
5 articulos

Genero:Masculino   Team Cristalab

Claber de baja indefinida

firefox
Citar            
MensajeEscrito el 20 Oct 2005 03:02 pm
estuve pensando en lo que me dijiste, lo unico que se me ocurrio (y que anda) es:
- Ordenar el XML (poner todos los nodos que tienen el mismo fabricante juntos)
- y ejecutar este bucle:

Código :

largo = parser.firstChild.childNodes.length;
   for (i=0; i<largo; i++) {
      uno = i+1;
      if (parser.firstChild.childNodes[i].attributes.fabricante == parser.firstChild.childNodes[uno].attributes.fabricante) {
         continue;
      } else {
         Fabricantes.push(parser.firstChild.childNodes[i].attributes.fabricante);
      }
   }

Solo de esta manera lo puedo hacer funcionar y que me seleccione solamente los que no estan repetidos ¿y si estan "desparramados" los nodos?¿que hago?. Por ahora con este buclecito anda

Por jon4

10 de clabLevel



 

_root.bsas_mc.casa_mc

opera
Citar            
MensajeEscrito el 20 Oct 2005 03:47 pm
ok, bueno te doy un ejemplo que hice:

en Actionscript:

Código :

var miXML:XML = new XML();
var arreglo:Array = new Array();
miXML.ignoreWhite = true;

miXML.load("archivo.xml");

miXML.onLoad = function (exito:Boolean){
   var i, long:Number;
   if (exito){
      long = this.firstChild.childNodes.length;
      i=0;
      while (i<long){
         if (!buscar(this.firstChild.childNodes[i].attributes.fabricante)){ //si no esta
            arreglo.push(this.firstChild.childNodes[i].attributes.fabricante); //lo insertamos
            trace (this.firstChild.childNodes[i].attributes.fabricante); //lo mostramo
         }
         i++;         
      }
      trace(arreglo.length);
   }
}

function buscar (palabra:String):Boolean{
   var i:Number;
   for (i=0; i<arreglo.length ;i++){
      if (palabra==arreglo[i]){
         return true; //ya esta
      }
   }
   return false; //no esta
}


y en xml

Código :

<vehiculos>
<vehiculo fabricante='Chevrolet' modelo='Astra' />   
<vehiculo modelo='Audi A4' fabricante='Audi' />
<vehiculo modelo='Peugeot 206 3P' fabricante='Peugeot' />
<vehiculo modelo='Peugeot 206 5P' fabricante='Peugeot' />
<vehiculo modelo='Peugeot 307' fabricante='Peugeot' /> 
</vehiculos>



solo adaptalo al comboBox :P

saludos :)

Por Maikel

BOFH

5575 de clabLevel

22 tutoriales
5 articulos

Genero:Masculino   Team Cristalab

Claber de baja indefinida

firefox
Citar            
MensajeEscrito el 19 Nov 2005 02:53 am
hola Maikel,
a lo referido...
como haría si el xml está dentro de un archivo php? éste es mi AS:

Código :

var datosProductos:Array = new Array();
var losDatos:Array = new Array();

//Cargamos el XML
miXML.ignoreWhite = true;
miXML.onLoad = function(success){   
//Cargamos y llenamos el array   
if (success){      
for (i=0; i<miXML.firstChild.firstChild.childNodes.length; i++){   
   datosProductos.addItem({etiquetas:miXML.firstChild.firstChild.childNodes[i].childNodes[0].firstChild,datos:miXML.firstChild.firstChild.childNodes[i].childNodes[1].firstChild});               }   
   productos_cmb.dataProvider = losDatos;
   losDatos.addItem({label:etiquetas[i]});                  }   
      }

miXML.load("http://localhost/productos.php");

Se que está errado, pero necesito jalar llenar el combo de una tabla., para no tener que mdificr el combo cuando quiera agregar otro item..
gracias...

Por juce2005

100 de clabLevel



 

msie

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.