Hello again fellow Wix users! Back with yet another small issue that I’m hoping someone can help me out with! After implementing all of the solutions that I’ve gotten help with from everyone so far, I’ve run across another problem that I can’t seem to solve or find help for in the forum / database. I can’t get the data that I’m calling via a reference field to change information when the dynamic page changes. It always calls the information from the first row of the field even when the page changes. Let me explain.
I have a dynamic page which is of course attached to a collection, ProductsDyn. I have another collection which I call “tags”. Tags is a very lengthy list of boolean fields, which correspond to the products in ProductsDyn. I know that I could combine them and just put the boolean fields in the ProductsDyn collection, but due to it’s length and the nature of my project, I really want to avoid doing that.
So, I thought that I could create a reference field in “tags” referencing the items in ProductsDyn. Then, when I use the ProductsDyn dynamic page, I can call the Boolean fields in “tags”, which are in rows that have reference fields referencing items in ProductsDyn.
This brings me to my problem. When I call the Boolean Field in tags, which I want to use to change the color of certain boxes, it will only use the information in row 1 of the Boolean Field, no matter which page of ProductsDyn that I am on. It was my understanding (which is very possibly completely wrong!) that if Tags contained a reference field pointing to ProductsDyn, that it would change rows based on which page of ProductsDyn was being displayed. Here is my code:
ProductsDyn= dataset1 , Tags= dataset2, (“folds” is a Boolean Field in the “Tags” collection)
$w.onReady(function () {
$w.onReady( () =>
{$w("#dataset2").onReady( () => {$w("#dataset1").onReady( () => {let itemObj = $w("#dataset2").getCurrentItem().folds;if(itemObj===true){$w("#box1").style.backgroundColor = "#ffff";
console.log("it's true");}else{$w("#box1").style.backgroundColor = "#ef0";
console.log("it's false");}} )} );});});
When I run a preview of this page, it turns up “true” regardless of which page I am on. I have confirmed that it is reading the Tags Boolean Field “folds” properly, because if I open the collection and change the first row to false, the preview pages also turn to false. This is of course on every page of ProductsDyn.
Is there some piece of code that I am missing to get the dynamic pages to reference the proper row of Tags when changed. Thank you very much for taking the time to help!
Andy