I want to use an IF clause inside a $w(#repeater)forEachItem (see below), but it does not work. Can anyone tell me how to do it.
Thx Stephan
export function makeRepeater2 () {
$w ("#repeater1").forEachItem( ($item, itemData, index) => (
if (itemData.plz.length === 0) {
console.log("Undefined PLZ")
itemData.plz = ""
}
}
Now I found how it works:
import wixData from 'wix-data'; let ddf_Kategorie; ddf_Kategorie = ""; let sf_Jahr; sf_Jahr= 2000; let sf_Bereich; sf_Bereich = 20; let ef_Text; ef_Text = "" let itemHausnummer = "" let itemAbstand = "" $w.onReady (() => { $w ("#repeater1").onItemReady( ($item, itemData, index) => { if (itemData.hausnummer === undefined) {itemAbstand = ""; itemHausnummer = ""} else {itemAbstand = " "; itemHausnummer = itemData.hausnummer} $item("#text9").text = itemData.plz + " " + itemData.ortsname $item("#text10").text = itemData.stasse + itemAbstand + itemHausnummer giveFilter() }) }) export function input1_keyPress(event) { setTimeout (() => { ef_Text = $w ("#input1").value console.log(ef_Text) giveFilter() },500) } export function dropdown1_change(event) { ddf_Kategorie = $w ('#dropdown1').value; if ((ddf_Kategorie) === "Alle Kategorien") { ddf_Kategorie = ""} console.log(ddf_Kategorie) giveFilter() } export function slider1_change(event) { sf_Jahr = $w ("#slider1").value console.log(sf_Jahr) giveFilter() } export function slider2_change(event) { sf_Bereich = $w ("#slider2").value console.log(sf_Bereich) giveFilter() } export function giveFilter () { $w('#dataset1').setFilter(wixData.filter() .contains ('abbildung', ef_Text) .contains('kategorie', ddf_Kategorie) .between ('aufnahmejahr', sf_Jahr - sf_Bereich - 0.5, sf_Jahr + sf_Bereich + 0.5)) }
THANKS for your prompt answer.
It seems in my export function "makeRepeater" the "let" and also the "if" statement is not allowed?? Any idea what to do?
Big THANKS again
Hi again,
Hi again,fem is - general speaking- how to manipulate data of a dataset going into a repeater. I have empty fileds in my dataset that then show show a "undefined" in the repeater view. This what I want to avoid.
Below my code so far. The code marked out in the onReady section was for testing, I thought it may work that way, seems not possible.
Thx again for any help.
Stephan
import wixData from 'wix-data'; let ddf_Kategorie; ddf_Kategorie = ""; let sf_Jahr; sf_Jahr= 2000; let sf_Bereich; sf_Bereich = 20; let ef_Text; ef_Text = "" // const totalItems = $w("#dataset1").getTotalCount(); // console.log(totalItems) $w.onReady(() => { $w("#dataset1").onReady(() => { // setTimeout (() => { $w("#dataset1").getItems(0, 1000) .then ((allRecords) => { // let countRecords = allRecords.items.lengh; // console.log (countRecords) // if (countRecords === 0) { // console.log("RecordCount=0"); // } else { // console.log("RecordCount>0"); // } // if (allRecords.items.hausnummer === 1 ) { // console.log("Hausnummer =1") // allRecords.items.hausnummer = 1 // } else { // console.log("Hausnummer not 1"); // allRecords.items.hausnummer = 999 // } // console.log (allRecords) }) console.log ("OnReadyDataSet") giveFilter() }) }) export function input1_keyPress(event) { setTimeout (() => { ef_Text = $w ("#input1").value console.log(ef_Text) giveFilter() },500) } export function dropdown1_change(event) { ddf_Kategorie = $w ('#dropdown1').value; if ((ddf_Kategorie) === "Alle Kategorien") { ddf_Kategorie = ""} console.log(ddf_Kategorie) giveFilter() } export function slider1_change(event) { sf_Jahr = $w ("#slider1").value console.log(sf_Jahr) giveFilter() } export function slider2_change(event) { sf_Bereich = $w ("#slider2").value console.log(sf_Bereich) giveFilter() } export function giveFilter () { setTimeout( () => { $w('#dataset1').setFilter(wixData.filter() .contains ('abbildung', ef_Text) .contains('kategorie', ddf_Kategorie) .between ('aufnahmejahr', sf_Jahr - sf_Bereich - 0.5, sf_Jahr + sf_Bereich + 0.5)) console.log ("GiveFilter") makeRepeater() },900) } export function makeRepeater () { setTimeout( () => { $w ("#repeater1").forEachItem( ($item, itemData, index) => ( $item("#text9").text = itemData.plz + " " + itemData.ortsname )) console.log ("MakeRepeater") makeRepeater1() },900) } export function makeRepeater1 () { setTimeout( () => { $w ("#repeater1").forEachItem( ($item, itemData, index) => ( // $w('#text10').hide() $item("#text10").text = itemData.stasse + " " + itemData.hausnummer )) console.log ("MakeRepeater1") },900) }
Thanks so far.
In my dataset is a field “plz“ that is sometimes empty. When I transfer plz into string the repeater shows there a text „undefined“, this I want to avoid with an if clause, but the if clause is not accepted there.
Hope you or someone knows what is wrong. Thx!
The problem is somewhere else.
Maybe the itemData.plz is undefined and thus has no length.
Also it is not clear what exactly you're trying to achieve by changing the value of the itemData.