Created
June 28, 2019 15:30
-
-
Save MacgyverMartins/bbad124b176393f365edb5d4a8a15dd0 to your computer and use it in GitHub Desktop.
Select de estado cidade para wix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For full API documentation, including code examples, visit http://wix.to/94BuAAs | |
import { getJSON } from 'wix-fetch'; | |
$w.onReady(function () { | |
getJSON('https://api.myjson.com/bins/1f4ht7').then(json => { | |
const estadosList = json.data.map(i => { | |
return { label: i.nome, value: i.nome } | |
}); | |
$w('#dropdown1').options = estadosList | |
$w('#dropdown1').onChange(event => { | |
let options_cidades = []; | |
let estado = event.target.value; | |
json.data.forEach(function (val) { | |
console.log('va', val); | |
if (val.nome == estado) { | |
val.cidades.forEach(function (val_city) { | |
options_cidades.push({ label: val_city, value: val_city }); | |
}); | |
} | |
}); | |
console.log('c', options_cidades); | |
$w("#dropdown2").options = options_cidades; | |
}) | |
//volta | |
$w('#dropdown6').options = estadosList | |
$w('#dropdown6').onChange(event => { | |
let options_cidades = []; | |
let estado = event.target.value; | |
json.data.forEach(function (val) { | |
console.log('va', val); | |
if (val.nome == estado) { | |
val.cidades.forEach(function (val_city) { | |
options_cidades.push({ label: val_city, value: val_city }); | |
}); | |
} | |
}); | |
console.log('c', options_cidades); | |
$w("#dropdown7").options = options_cidades; | |
}) | |
//fim getJSON | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment