I have an array that is retrieved from a previous code, the array length and content is not predictable. I want to loop through that array and use each element of the array to filter a query and fill repeater containers. Basically how do I get the index of each container in a repeater and replace it with the loop index and fill the specific container with the result of the loop query that pertains to the container.
arrayy = [a,b,c,d]
for(let i=0; i<arrayy.length;i++){
let fill = wixData.query(“ALL”)
.eq(“allid”,array[i])
Promise.all([fill.limit(1000).find()])
.then((res)=>{
let returned = [res[0].items].flat()
$w(“#datasetfill”).setCurrentItemIndex(i) = returned//This where I have the problem, repeater is connected to this dataset
$w(“#repeaterfill”).container= returned//Or can I populate each container based on there index value?
})
}//end of loop
The populated repeater is expected to have the number of containers as the arrayy length
arrayy = [a,b,c,d]
$w(“#datasetfill”).onItemReady(($item,itemData,index=>{
$item (“#Title”). text= itemData . title ;
}
for(let i=0; i<arrayy.length;i++){
let fill = wixData.query(“ALL”)
.eq(“allid”,array[i])
Promise.all([fill.limit(1000).find()])
.then((res)=>{
let returned = [res[0].items].flat()
$w(“#datasetfill”).data[i] = returned
})
}//end of loop, This doesnt work
You are using code for DATASET, which was created for using for REPEATERS!
Or is → #datasetfill ← the ID of your REPEATER ???
Not logical & systematical coding-practise !
Without to observe the rest of your code, first show a screen of your DB and tell me what you want to achieve?
Yes it is possible! But i think you will have also other possibilities.
I assume you are trying to filter an ARRAY-DATA inside your DB or a SELECTION-TAG-FIELD or something like that, right?
If so, there are also other methods and techniques how to do it.
Thanks for the response
within this as the loop fills each container data with the looped objects inside the items array, how do I change the container color within the same loop?
I am trying to filter the items array inside the DB
results = {items:[{colarowa,colbrowa,…},{colarowb,colbrowb,…},{colarowc,colbrowc}]}
I am trying to loop through objects inside the items array that fit a query criteria so that the returned objects will populate the repeater containers. The criteria and how many times the loop will occur is not specific, it will be determined by the length of the array and contents.
As you may know the contents of the array are ids that are compared with the “allid” in the “ALL” DB
let arrayy = [a,b,c,d]
$w(“#repeaterfill”).onItemReady(($item,itemData,index=>{
$item (“#Title”). text= itemData . title ;
}
for(let i=0; i<arrayy.length;i++){
let fill = wixData.query(“ALL”)
.eq(“allid”,array[i])
Promise.all([fill.limit(1000).find()])
.then((res)=>{
let returned = [res[0].items].flat()
$w(“#repeaterfill”).containercolor = “red”// something like this
$w(“#repeaterfill”).data[i] = returned[i]
})
}
Maybe you did not get what I am trying to do, I only need to loop through the array of objects and fill the repeater with whatever is contained in the object as I have already connected the objects data(itemData) to all the elements in each container of the repeater. What I don’t get is how to get the index of each container that is looped(not the data inside) and change the background color for each container per loop.
Yeah perhaps i did not understand you right.
Perhaps you will need a loop in a loop.
let arrayA = ["1","2","3","4","5"];
let arrayB = ["a","b","c","d","e"];
for (let a = 0; a < arrayA.length; a++) {
for (let b = 0; b < arrayB.length; b++) {
console.log(arrayA[a]+arrayB[b]);
}
}
Also take a look onto this example, to be found here in this parallel running post…