Ola, eu tenho duas tabelas uma com o nome Planos e outra com o nome Planos_Meses e tenho dois select options o primeiro com o nome dos planos e o segundo com os meses de adesão, eu fiz um relacionamento entre as tabelas, mas não estou conseguindo montar os resultados direito, eu preciso que o segundo select funcione pegando os boleto_id dinamicamente e alterando o button com a url.
Você pode visualizar aqui https://www.spaceiptv.net/testes
Sera que alguém consegue me ajudar?


import wixData from "wix-data";
let planoSelected
let planoVip = []
let planoTitle = []
let planoPaypal = []
let planoBoleto = []
let targ
let link
$w.onReady(function () {
$w('#dropdown1').disable()
});
export function dropdown2_change(event) {
targ = event.target.value
wixData.query("Planos_Meses")
.find()
.then( (results) => {
let val = results.items
//
val.forEach((i) => {
if (i.plano_id === targ) {
planoVip.push(i)
planoTitle.push(i.title)
//planoPaypal.push(i.paypal_id)
planoBoleto.push(i.boleto_id)
}
})
// planoBoleto = []
})
//buildOptions()
$w('#dropdown1').enable()
getPlanos()
}
function getPlanos() {
$w("#dropdown1").onChange( (eventTwo) => {
planoSelected = eventTwo.target.value
//console.log(planoSelected, planoBoleto)
})
let ver = $w("#dropdown1").options
console.log(ver)
if (planoSelected === "12") {
//$w("#button15").link = setLink("TPGGLUD9QGYVE", "paypal")
link = setLink(planoBoleto[0], "boleto")
$w("#button16").link.replace(link, link)
}
else if(planoSelected === "6") {
link = setLink(planoBoleto[1], "boleto")
//$w("#button15").link = setLink("J5TR9AVJ27V9C", "paypal")
$w("#button16").link = link
}
else if(planoSelected === "3") {
//$w("#button15").link = setLink("FZ2HU72Q9ACTC", "paypal")
$w("#button16").link = setLink(planoBoleto[2], "boleto")
}
else if(planoSelected === "1") {
// $w("#button15").link = setLink("FUKB4WNM55E4S", "paypal")
$w("#button16").link = setLink(planoBoleto[3], "boleto")
}
//console.log($w("#dropdown1").options);
function setLink($id, $gateway) {
return ($gateway === 'paypal') ?
"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id="+$id :
"https://www.boletobancario.com/boletofacil/integration/button/checkout.html?code="+$id;
}
}
Hello @Erlan Carreira Olhando o seu código percebi que as condições(if) que verificava o tipo de plano estava incompleta. Abaixo estarei dando um exemplo de código corrigido
Correção:
import wixData from "wix-data"; let planoSelected let planoVip = [] let planoTitle = [] let planoPaypal = [] let planoBoleto = [] let targ let link $w.onReady(function () { $w('#dropdown1').disable() }); export function dropdown2_change(event) { targ = event.target.value wixData.query("Planos_Meses") .find() .then((results) => { let val = results.items // val.forEach((i) => { if (i.plano_id === targ) { planoVip.push(i) planoTitle.push(i.title) //planoPaypal.push(i.paypal_id) planoBoleto.push(i.boleto_id) } }) // planoBoleto = [] }) //buildOptions() $w('#dropdown1').enable() getPlanos() } function getPlanos() { $w("#dropdown1").onChange((eventTwo) => { planoSelected = eventTwo.target.value //console.log(planoSelected, planoBoleto) }) let ver = $w("#dropdown1").options console.log(ver) if (planoSelected === "12 Meses") { //$w("#button15").link = setLink("TPGGLUD9QGYVE", "paypal") link = setLink(planoBoleto[0], "boleto") $w("#button16").link.replace(link, link) } else if (planoSelected === "6 Meses") { link = setLink(planoBoleto[1], "boleto") //$w("#button15").link = setLink("J5TR9AVJ27V9C", "paypal") $w("#button16").link = link } else if (planoSelected === "3 Meses") { //$w("#button15").link = setLink("FZ2HU72Q9ACTC", "paypal") $w("#button16").link = setLink(planoBoleto[2], "boleto") } else if (planoSelected === "1 Meses") { // $w("#button15").link = setLink("FUKB4WNM55E4S", "paypal") $w("#button16").link = setLink(planoBoleto[3], "boleto") } //console.log($w("#dropdown1").options); function setLink($id, $gateway) { return ($gateway === 'paypal') ? "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=" + $id : "https://www.boletobancario.com/boletofacil/integration/button/checkout.html?code=" + $id; } }
Espero que agora dê certo!