2016-03-21 16 views
2
for (a = 1; a <= 2; a++) { 

    $("#inp-" + a + " .nama").autocomplete({ 
    source: function(request, response) { 
     $.ajax({ 
     url: "states_remote.php", 
     dataType: "json", 
     data: { 
      term: request.term 
     }, 
     success: function(data) { 
      response($.map(data, function(item) { 
      return { 
       value: item.nama, 
       pangkat: item.pangkat, 
       jabatan: item.jabatan, 
       nip: item.nip 
      }; 
      })); 
     } 
     }); 
    }, 
    minLength: 2, 
    select: function(event, ui) { 
     $("#inp-" + a + " .pangkat").val(ui.item.pangkat); 
     $("#inp-" + a + " .nip").val(ui.item.nip); 
     $("#inp-" + a + " .jabatan").val(ui.item.jabatan); 

     $(this).next('.nama').focus(); 
    }, 
    html: true, 
    open: function(event, ui) { 
     $(".ui-autocomplete").css("z-index", 1000); 
    } 
    }); 
} 

i autocomplate seçme fonksiyonu içine döngü değişkeni a kullanmak istiyorum, ama bu işlev değişkeni çağırmak erişmek olamaz çağrılması döngü değişkeni benim sorun çözüldü için

select: function(event, ui) { 
    $("#inp-" + a + " .pangkat").val(ui.item.pangkat); 
    $("#inp-" + a + " .nip").val(ui.item.nip); 
    $("#inp-" + a + " .jabatan").val(ui.item.jabatan); 

    $(this).next('.nama').focus(); 
}, 

birisi bana yardımcı olabilir

seçmek? diğer konuya göre arama yapabilirim belki bu isim asenkron işlevdir.

cevap

0

bir kapatma kullanmayı deneyin: - Başka bir yolu yoktur

for (a = 1; a <= 2; a++) { 
 

 
    (function(a) { 
 

 
    $("#inp-" + a + " .nama").autocomplete({ 
 
     source: function(request, response) { 
 
     $.ajax({ 
 
      url: "states_remote.php", 
 
      dataType: "json", 
 
      data: { 
 
      term: request.term 
 
      }, 
 
      success: function(data) { 
 
      response($.map(data, function(item) { 
 
       return { 
 
       value: item.nama, 
 
       pangkat: item.pangkat, 
 
       jabatan: item.jabatan, 
 
       nip: item.nip 
 
       }; 
 
      })); 
 
      } 
 
     }); 
 
     }, 
 
     minLength: 2, 
 
     select: function(event, ui) { 
 
     $("#inp-" + a + " .pangkat").val(ui.item.pangkat); 
 
     $("#inp-" + a + " .nip").val(ui.item.nip); 
 
     $("#inp-" + a + " .jabatan").val(ui.item.jabatan); 
 

 
     $(this).next('.nama').focus(); 
 
     }, 
 
     html: true, 
 
     open: function(event, ui) { 
 
     $(".ui-autocomplete").css("z-index", 1000); 
 
     } 
 
    }); 
 

 
    })(a); 
 

 
}

+0

Çok teşekkür ederim, sorun çözüldü – Wisnu

0

ve ben o biri daha iyi olurdu hissediyorum:

$(".nama").autocomplete({ // <----all the ".nama" element will be initialized 
    source: function(request, response) { 
    $.ajax({ 
     url: "states_remote.php", 
     dataType: "json", 
     data: { 
     term: request.term 
     }, 
     success: function(data) { 
     response($.map(data, function(item) { 
      return { 
      value: item.nama, 
      pangkat: item.pangkat, 
      jabatan: item.jabatan, 
      nip: item.nip 
      }; 
     })); 
     } 
    }); 
    }, 
    minLength: 2, 
    select: function(event, ui) { 
    // event.target will be the ".nama" element and 
    // as per your code it seems that the elements are sibling 
    // elements of the ".nama", so use `.end()` to get back to 
    // $(event.target) 
    $(event.target).siblings(".pangkat").val(ui.item.pangkat).end() 
        .siblings(".nip").val(ui.item.nip).end() 
        .siblings(".jabatan").val(ui.item.jabatan); 

    $(event.target).focus(); 
    }, 
    html: true, 
    open: function(event, ui) { 
    $(".ui-autocomplete").css("z-index", 1000); 
    } 
}); 
+0

Döngü nerede? Değeri girmek için farklı sınıf ilan etmeliyim – Wisnu