Hello again fellow Wix users!
I’m having what I believe to be a small problem that I am just not understanding properly and hope that someone else may be able to help. I really appreciate any time that you may be able to spend on this. I am fairly new to this, so please understand that even my theorizing may be inaccurate!
I’m trying to get a box on dynamic pages to change colors based on a boolean field in the dataset (I’ve already posted about this, but the core problem has changed, and, as per the forum guidelines, I’m making a new post rather than bumping the old one).
I’ve managed to do that, but now I can’t seem to get it to query the row corresponding to the current dynamic page. It seems like no matter which page I preview, the result is the same, even though the boolean for the current page has changed. This is confirmed by the console.log. Originally, I had teh following code which returned the following log:
wixData.query("ProductsDyn")
.eq("creases", true)
.find()
.then( (results) => {
console.log("results [0] returned from query = " + JSON.stringify(results.items[0]));
let boolean = results.items[0];
if(boolean===true){
$w("#box2").style.backgroundColor = "#ffff";
console.log("it's true");
}
else{
$w("#box2").style.backgroundColor = "#ef0";
console.log("it's false");
}
} )
.catch( (err) => {
let errorMsg = err;
} );
Loading the code for the Products (Dyn) (Title) page. To debug this code, open ae518.js in Developer Tools.
results [0] returned from query = {"image":"wix:image://v1/fc7570_ae9913d461894a7ebb7fc420d828ab83~mv2.png/Image-empty-state.png#originWidth=1920&originHeight=1080","description":"I'm a paragraph. I'm connected to your collection through a dataset. Click Preview to see my content. To update me, go to the Data Manager.","_id":"00000000-0000-0000-0000-000000000001","_owner":"c8bffc82-3f37-4541-a85b-1c3af9a932e7","_createdDate":"2021-02-15T09:13:59.833Z","_updatedDate":"2021-02-15T15:57:38.101Z","whoKnows":["Mint","New Type","Near Mint"],"creases":true,"title":"I am a title 01","link-products-dyn-all":"/products-dyn/","link-products-dyn-title":"/products-dyn/i-am-a-title-01"}
Products (Dyn) (Title)
Line 9
it's false
It makes sense that the console.log information wouldn’t change because I’m calling a specific field (items[0]). So, I thought that I should insert “currentPage” where “items[0]” is. However, this doesn’t return any information in the log:
import wixData from 'wix-data';
wixData.query("ProductsDyn")
.eq("creases", true)
.find()
.then( (results) => {
console.log("results [0] returned from query = " + JSON.stringify(results.currentPage));
let boolean = results.currentPage.creases;
if(boolean===true){
$w("#box2").style.backgroundColor = "#ffff";
console.log("it's true");
}
else{
$w("#box2").style.backgroundColor = "#ef0";
console.log("it's false");
}
} )
.catch( (err) => {
let errorMsg = err;
} );
Loading the code for the Products (Dyn) (Title) page. To debug this code, open ae518.js in Developer Tools.
results [currentPage] returned from query = 0
Products (Dyn) (Title)
Line 9
it's false
I have tried many variations and commands without any success. What am I missing here?!
Thanks in advance for any advice you may be able to offer!
Andy