JQuery JSon combo dinamico 20 de maio de 2009 Neyvo Souza Post in Jquery Para fazer um combo dinamico com JQuery e JSon é muito simples! crie um arquivo JSon com o nome situacao.json e com o seguinte conteudo: {“situacao”:[{“id”:2,”nome”:”FECHADO”},{“id”:3,”nome”:”ANDAMENTO”},{“id”:1,”nome”:”ABERTO”}]} e um arquivo html com o seguinte conteudo: <html> <head> <script src=”./js/jquery.js”></script> <script> $(document).ready(function(){ $.getJSON(“situacao.json”, function(data){ $.each(data.situacao, function(i,item){ $(“#links”).append(“<option value='”+item.nome+”‘>”+item.nome+”</option>”); }); }); }); </script> </head> <body> <select id=”links”> </select> </body> </html> Até mais. ——————————— Ale, tenta esse código <html> <head> <script src=“http://code.jquery.com/jquery-latest.js”></script> <script> $(document).ready(function(){ $.getJSON(“Estados.json”,function(data){ $.each(data.Estados, function(i,item){ $(“#IDESTADO”).append(“<option value='”+item.nome+“‘>”+item.nombre+“</option>”); }); }); }); </script> </head> <body> <select id=“IDESTADO”> </select> </body> </html>
Ayuda por favor no puedo realizar mi combo dinamico este es mi codigo lista = “Estados: [“; for (int x = 0; x < vecFinal.size(); x++) { vecEstados = (Vector) vecFinal.get(x); lista += “{” +”\””+”id”+”\””+”:”+ vecEstados.get(0) + “,” +”\””+”nombre”+”\””+”:”+ ” \”” + vecEstados.get(1) +”\””+ “}” + “,”; } System.out.println(“{” + lista +”}”);
Un ejemplo con JSP <% String lista = "\"paises\": ["; String vecFinal[] = {"Brasil","Espanha","Italia"}; String vecEstados = ""; for (int x = 0; x < vecFinal.length; x++) { vecEstados = vecFinal[x]; lista += "{" +"\""+"id"+"\""+":"+ (x+1) + "," +"\""+ "nome"+"\""+":"+ " \"" + vecEstados +"\""+ "}" + ","; } out.println("{" + lista +"]}"); %>
Hola gracias por conetsr tan rapido la verdad no he podido resolver mi problema oye te puedo pasasr por correo mis codigos y haber si me puedes orientar por favor la verdad es un problema q no he podido solucionar me podras pasar tu correo admin say
Pues no {“Estados”:[{“id”:1,”nombre”: “Mexico”},{“id”:2,”nombre”: “Morelia”},{“id”:3,”nombre”: “Morelos”},]} es mi repuesta json Y este es mi codigo juery function buscar(){ $.getJSON(“Estados.json”, function(data){ $.each(data.Estados, function(i,item){ $(“#IDESTADO”).append(“”+item.nombre+””); }); }); } Xfavor ayuda no he podido realizar mi combo
Hello!I am following your posts for some days now. I have to admit that it is very informative. It is added in my bookmarks and i will make sure that i will follow it frequently. Thanks for the nice posts . Furthermore, i really like your theme and the way you have structured the contents of your site . Is it possible to tell me the name of your template ? Thanks
What i find difficult is to find a blog that can capture me for a minute but i think you offer something different. Bravo.
I really enjoyed the article. It is always nice when you can not only be informed, but also entertained!
O Código correto está aqui: {HTML} $(document).ready(function(){ $.getJSON(“situacao.json”, function(data){ $.each(data.situacao, function(i,item){ $(“#links”).append(“”+item.nome+””); }); }); }); {situacao,json} {“situacao”:[{“id”:2,”nome”:”FECHADO”},{“id”:3,”nome”:”ANDAMENTO”},{“id”:1,”nome”:”ABERTO”}]}