Hello, so the concept is:
We have some data coming in from a function each time the loop runs, and we want this data to be placed on an object[i] each time.
while (totalCount > 0) {
var f1= result.items[i].f1;
var f2= result.items[i].f2;
calc($w("#input1").value, result, i).then(product => {
//HERE res[i].field1= f1;
//HERE res[i].field2= f2;
//HERE res[i].field3= product;
})
i = i + 1;
totalCount = totalCount - 1;
}
I’m not sure how i can do it…
I basically want after some times that it will run to have res[1],res[2],res[3] etc. objects with each one having their own values.
//res at the end of the loop:
res[1].field1= “f1_value”;
res[1].field2= “f2_value”;
res[1].field3= “f3_value”;
res[2].field1= “f1_value”;
res[2].field2= “f2_value”;
res[2].field3= “f3_value”;
And then just parse this data of res to a repeater
repeater.data = res.
Hi Athanasios ,
is this wix code specific question or general javascript issue?
Shlomi
Im trying to filter data from the collection and display it on a repeater on a specific way
Hi,
a repeater is based on a dataset which is based on a collection to which you can add filters and sorts (in the data set)
try looking into https://www.wix.com/code/reference/$w.Repeater.html#forEachItem and other repeater api-s which you may find useful
Shlomi
I Dont want to populate the repeater from a dataset, i want to first have the data on an object and then set that object to populate the repeater using $repeater.data = object. I Just Cant figure out how to create that object In the For loop.
Can you please share more information about what you are trying to achieve
I want to calculate the distances between the user’s address and some of the properties listed on the database.
Let’s say we have on the database Property A, Property B, Property C.
The user will input on the search page his address, let’s call it user_address.
Now using google’s api and some js we are calculating that distance using the calc() function as you can see on the code.
All that is on a loop that runs for all properties(the totalcount is from a query happened before on the code to query all the properties - basically an empty wix.data find() to grab every entry of the database).
All the above is ready and working, the only thing i need help with is that:
Basically i’m sure this is quite simple i’m just missing something here on an object is called.
So as you can see after the .then a variable is returned which contains the distance.
the f1 and f2 are property name and address that got grabbed before from the database.
What i need is each time save that information on an object.
So i guessed an result(i) where i is the number of loop, so we will have result(1) result(2) result(3) etc. where each result will have the .field1 .field2 .field3 properties.
And then i will just use $repeater.data = result to populate the repeater.
I just need that…how to define the object result(i) each time and save it some data…
while (totalCount > 0) {
var f1= result.items[i].f1;
var f2= result.items[i].f2;
calc($w("#input1").value, result, i)
.then(product => {
res[i].field1= f1;
res[i].field2= f2;
res[i].field3= product;
})
i = i + 1;
totalCount = totalCount - 1;
}
Hi,
did you set the _id property as well? try to log the results structure and see that the data i set is in a similar structure only with an added calculated field.
the repeater should also have the context of paging so not all of the data is loaded in advance
once you get this working, further look into a performance issue you have, is invoking a count in a loop. so if you have 100 properties, you can 100 ajax round trips, one after the other, all the way from the client browser (geographic location) to wix servers and back, before the page is displayed.
Shlomi