Foros del Web » Programando para Internet » Jquery »

variables globales

Estas en el tema de variables globales en el foro de Jquery en Foros del Web. Hola: Necesito manejar variables globales para almacenar en un array varios valores: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original var wil = new Array ( ...
  #1 (permalink)  
Antiguo 19/06/2013, 16:19
 
Fecha de Ingreso: enero-2010
Mensajes: 491
Antigüedad: 14 años, 3 meses
Puntos: 12
variables globales

Hola:

Necesito manejar variables globales para almacenar en un array varios valores:
Código Javascript:
Ver original
  1. var wil = new Array();
  2.         $( "#tags" )
  3.             // don't navigate away from the field on tab when selecting an item
  4.             .bind( "keydown", function( event ) {
  5.                 wil = new Array();
  6.                 if ( event.keyCode === $.ui.keyCode.TAB &&
  7.                         $( this ).autocomplete( "instance" ).menu.active ) {
  8.                     event.preventDefault();
  9.                 }
  10.             })
  11.             .autocomplete({
  12.                 minLength: 0,
  13.                 source: function( request, response ) {
  14.                     // delegate back to autocomplete, but extract the last term
  15.                     response( $.ui.autocomplete.filter(
  16.                         availableTags, extractLast( request.term ) ) );
  17.                 },
  18.                 focus: function() {
  19.                     // prevent value inserted on focus
  20.                     return false;
  21.                 },
  22.                 select: function( event, ui ) {
  23.  
  24.                     var terms = split( this.value );
  25.                     var ff;
  26.                     // remove the current input
  27.                     terms.pop();
  28.                     // add the selected item
  29.                     terms.push( ui.item.value );
  30.                     // add placeholder to get the comma-and-space at the end
  31.                     terms.push( "" );
  32.                     this.value = terms.join( ", " );
  33.                     wil[ui.item.id]=ui.item.id
  34.                     alert(wil[ui.item.id]);
  35.                     alert(wil[1]);
  36.                     $('#hiddenAllowSearch').val(ui.item.id);
  37.                     return false;
  38.                 }
  39.             });
Los alert imprimen bien cuando es la primera ves pero para una segunda el primer alert imprime el valor que corresponde pero el segundo alert imprime undifinied, y si selecciono un valor en wil[1].
  #2 (permalink)  
Antiguo 20/06/2013, 07:33
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: variables globales

consulte sobre los temas de scope y closures en JS, para que tenga una más clara idea de lo que está haciendo.
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...

Etiquetas: globales, variables
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 08:25.