我有一个加载多行Json字符串的函数。我试图使用它来填充select
元素,但它不起作用。我想在JQM网站上应用它
这是函数
function loadgeo2Adminii1(value,child,loading,vd,ponerfocus){
if(parseInt(value,10) > 0){
var url= UrlServer+'index.php?im_core=jsonSearchColonia&im_geo='+value;
$('#im_texto_'+child).val('').selectmenu( "disable" );
$('#im_'+child).val('');
$.get(url,function(data){
data.sort(function(a,b){
if(a.id.toLowerCase()== vd[1].toLowerCase() || b.id.toLowerCase()== vd[1].toLowerCase() )bandera = 1;
var aName = remove_accents(a.label.toLowerCase());
var bName = remove_accents(b.label.toLowerCase());
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));}
);
$( '#im_texto_g2').selectmenu( "enable" );
jQuery.each(function(data){
$("#im_texto_g2").find('#im_texto_g2-button').append('<option value="'+data.id+'">'+data.label+'</option>');});
},'json');
}
else{
$('#im_texto_g2'.val('').selectmenu( "disable" );
$('#im_'+child).val('');
}
}
注意:我可以看到Firebug
中的响应显示包含大量子字符串的Json字符串。这是子字符串
另外,如果你看一下我的剧本的以下部分
$( '#im_texto_g2'+child ).find('#im_texto_g2-button').selectmenu( "enable" );
jQuery.each(data,function(i,item){
console.log(item,i);
$("#im_texto_g2").append('<option value="'+item.id+'">'+item.label+'</option>');
});
我正在尝试填充选项标记。
谢谢&amp;问候
答案 0 :(得分:1)
jQuery.each(function(data){
使用jQuery.each()
是错误的,正确的语法是
jQuery(array).each(fn)
或jQuery.each(array, fn)