0
I have the following json:
And 2 selects, one for state and one for city, I have already filled the status correctly using this json:
//combobox estados
$.getJSON('http://api.doupenglish.com.br/unidades', function (unidades) {
var selectestado = $("#selectestado");
var selectcidade = $("#selectcidade");
var estados = unidades.Estados;
//não consigo recuperar as cidades do json aqui
var cidades = unidades.Estados.values;
// console.log(cidades)
var optionsestados = '<option hidden >Selecione um estado</option>';
$.each(estados, function (estado) {
optionsestados += '<option value="' + estado + '">' + estado + '</option>';
});
selectestado.html(optionsestados);
selectestado.change(function () {
var estadoselecionado;
selectestado.find("option:selected").each(function () {
estadoselecionado = $(this).text();
console.log(estadoselecionado)
});
})
});
I need that when selecting a state it lists all the cities of that state, the problem is that I am not able to get the "list" of cities in this json, tried several things but without success. I don’t know if it’s the json that is badly "formatted" but since I don’t have a key to the cities, I can’t access.
EDIT I was able to get an object from the cities:
$.each(estados, function (estado, cidades) {
if (estado === estadoselecionado){
console.log(cidades)
}
});
However I still can’t get the values of this object as name, street etc
tried
data[0].bairro
?– adventistaam
@adventistaam yes, from Uncaught error Typeerror: Cannot read Property 'neighborhood' of Undefined
– Igor Oliveira
if you put in return javascript
console.log( data )
what returns?– adventistaam
I don’t use the variable with name date, but I think you are referring to the json received with name of units, then return me this: http://prntscr.com/ioq50o
– Igor Oliveira
The same full json
– Igor Oliveira
Actually date means given in English, try
cidades[0].bairro
what happens?– adventistaam
Exactly like my first comment ( I had done with cities)
– Igor Oliveira
Let’s go continue this discussion in chat.
– adventistaam