Created
June 30, 2020 06:26
-
-
Save shanwixcode/8326b89955a8478f2b521272bc949517 to your computer and use it in GitHub Desktop.
This file contains 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
import wixData from 'wix-data'; | |
$w.onReady(function () { | |
}); | |
export function dataset1_ready() { | |
$w("#repeater1").onItemReady( ($item, itemData, index) => { | |
$item("#price").text = itemData.price + ' ' + itemData.currency; | |
}); | |
} | |
let lastFilterName; | |
let lastFilterPrice; | |
let debounceTimer; | |
function filter(name, price) { | |
if (lastFilterName !== name || lastFilterPrice !== price) { | |
let newFilter = wixData.filter(); | |
if(name) | |
newFilter = newFilter.contains('name', name); | |
if(price) | |
newFilter = newFilter.le('price', price); | |
$w("#dataset1").setFilter(newFilter); | |
lastFilterName = name; | |
lastFilterPrice = price; | |
} | |
} | |
export function searchBar_keyPress(event) { | |
if (debounceTimer) { | |
clearTimeout(debounceTimer); | |
debounceTimer = undefined; | |
} | |
debounceTimer = setTimeout(() => { | |
filter($w("#searchBar").value, lastFilterPrice); | |
}, 200); | |
} | |
export function slider1_change(event) { | |
let num = Number($w('#slider1').value); | |
filter(lastFilterName, num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment