javascript - Can't get correct values from each statement -


i have object (called alluserinfo that's this:

object { available_client_ids: array[2] 0: "demo" 1: "4532t78" available_client_names: array[2] 0: "demo" 1: "bobs bakery" email: "jmr@example.com } 

i need available_client_ids , available_client_names, keep coming undefined or worse. i'm trying this:

$.each(alluserinfo, function(index, value) { $('.clients_available3').append("<option>" + index.available_client_names + "</option>");    }); 

this give me many undefined things appended select (clients_available3). needs like:

$.each(alluserinfo.available_client_names, function(index, value) { $('.clients_available3').append("<option>" + index.available_client_names + "</option>");    }); 

but doesn't work either.

edit

if this,

   $.each(alluserinfo.available_client_names, function(index, value) {                 $('.clients_available3').append("<option>" + value + " </option>"); }); 

this works , gives me client names, don't have way ids. hoping them both, doesn't work:

 $.each(alluserinfo, function(index, value) {                 $('.clients_available3').append("<option value="+available_client_ids+">" + available_client_names.value + " </option>"); }); 

use native javascript loop:

for(var i=0; i<alluserinfo.available_client_names.length){     var name = alluserinfo.available_client_names[i];     var id = alluserinfo.available_client_ids[i];     $('.clients_available3').append("<option value='"+id+"'>" + name + "</option>"); } 

or update original code following:

$.each(alluserinfo.available_client_names, function(index, value) {    $('.clients_available3').append("<option value='"+alluserinfo.available_client_ids[index]+"'>" + available_client_names[index] + "</option>");    }); 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -