- You start like -->ALWAYS<— with …
$w.onReady(()>{.........................});
- When working with DATASETS → a DATASET has to be ready first!!!
$w.onReady(()>{
$w('#dynamicDataset').onReady(()=>{
});
});
- You get the current-data out of your DB with the help of your DATASET (in this case a dynamic one…
$w.onReady(()>{
$w('#dynamicDataset').onReady(()=>{
let curData = $w('#dynamicDataset').getCurrentItem();
console.log("Current-Data: ", curData);
});
});
Now take a look onto the —> CONSOLE !
What do you get as RESULT ?
You should get something like an OBJeCT —> {…}
Open the OBJECT, by a click onto it.
You will be able to see all DATA of current selected ITEM (loaded from the DATABASE) including the COLORS-FIELD + DATA.
- Once you got that data, you can now load it into your REPEATER…
$w('#myRepeaterIDhere').data = curData
…or…
$w('#myRepeaterIDhere').data = curData[0]
…or
$w('#myRepeaterIDhere').data = curData[0].items
- Now you need to connect your REPEATER to the whole process…
Your REPEATER now must react when it got new data…this can be done by…
$w('#myRepeaterIDhere').onItemReady(($i, iData, index)=>{
.......
});
- Now you need to know what is inside of your REPEATER (which elements) ???
You have a —> box inside of your REPEATER → ‘#box1’
$w('#myRepeaterIDhere').onItemReady(($i, iData, index)=>{
$i("#box1").style.backgroundColor="rgba(255,0,0,0.5)";
});
So at the end you must have something like the following…
$w.onReady(()>{
$w('#dynamicDataset').onReady(()=>{
let curData = $w('#dynamicDataset').getCurrentItem();
console.log("Current-Data: ", curData);
});
$w('#myRepeaterIDhere').onItemReady(($i,iData,index)=>{
//Here we are giving a fixed color for the box.
$i('#box1').style.backgroundColor='rgba(255,0,0,0.5)';
//Now let's load the color from DB...
$i('#box1').style.backgroundColor='rgba('+myColor+')';
});
});
data must be a string like ----> 255,0,0,0.5 <---- inside your DB.
- But first you have to get that data from your curData…
let myColor = curData[0].colours;
console.log("My-Found-Color: ", myColor);
Now, everytime you switch the DYNAMIC PAGE to show next item, each of the items should have an own colorized box.
You have here just an example. You surely will have to modify a little bit.
But the main process is described in detail.
EDIT: The same way you can use a HEX-VALUE inside of your DB, which would even be easiert to use.
EXAMPLE inside DB-FIELD (colours) —> #Fd5030 <—whatever color
let myColor = curData[0].colours;
console.log("My-Found-Color: ", myColor);
$i('#box1').style.backgroundColor= myColor