top of page

Ordenar y filtrar bases de datos | Curso Velo



Bienvenido y espero que estés muy bien. Este es el cuarto video del CURSO DE VELO EN WIX. Una serie de videos que te ayudará a entender Velo de Cero a Intermedio. No olvides subscribirte y comentar alguna pregunta!





CÓDIGO

 

// Velo API Reference: https://www.wix.com/velo/reference/api-overview/introduction import wixData from 'wix-data'; $w.onReady(function () { init(); }); async function init() { loadProduct(false, '', ''); $w("#repeater8").onItemReady(($item, itemData, index) => { $item("#text14").text = itemData.price.toString(); $item("#text13").text = itemData.title; $item("#container8").background.src = itemData.imageMain; }); $w("#dropdown1").onChange((ev) => { const price = $w("#dropdown1").value; const priceNumber = parseInt(price); loadProduct(true, 'price', priceNumber) }) $w("#button10").onClick((ev) => { loadProduct(false, '', ''); $w("#dropdown1").value = undefined; }) $w("#name").onInput(() => { const nameString = $w("#name").value; $w("#dataset1").setFilter(wixData.filter() .contains("title", nameString) ); }) } async function loadProduct(filter, field, value) { let products; if (filter) { products = await wixData.query("products") .descending('title') .eq(field, value) .find() .then((results) => { if (results.items.length > 0) { // console.log(results.items[0]); //see item below return results.items; } else { // handle case where no matching items found return []; } }) } else { products = await wixData.query("products") .descending('title') .find() .then((results) => { if (results.items.length > 0) { // console.log(results.items[0]); //see item below return results.items; } else { // handle case where no matching items found return []; } }) } console.log("products", products); $w("#repeater8").data = products; }



 
71 views0 comments
bottom of page