javascript - Splitting an array before adding to combo list -
i have json object returns several key value pairs. 1 of languages key , contains comma separated values e.g "english, hindi,french" etc
i'm trying split array before adding combo list, try fails. can help, please?
$('#combolist-languages').html(function () { var ret = '<option value="-1" selected>select language_</option>', u = user.slice(), arr = []; (function get() { if (u.length) { var v = u.shift(); if ($.inarray(v.languages, arr) == -1) { arr.push(v.languages); ret += '<option value="">' + v.languages + '</option>'; } get(); } }()); return ret; });
i'm not sure put split function. thanks!
what that?
var lang = 'english,hindi,french'; var html = '<option value="-1" selected>select language_</option>'; html += '<option value="">'; html += lang.split(',').join('</option><option value="">'); html += '</option>'; $('#combolist-languages').html(html);
setting value each option jquery.map
:
var lang = 'english,hindi,french'; var html = '<option value="-1" selected>select language_</option>'; $('#combolist-languages').html( html + jquery.map(lang.split(','), function (text, value) { return '<option value="' + value + '">' + text + '</option>'; }) );
Comments
Post a Comment