Hello guys,
I am new with coding but trying hard to understand the logic.
I have a database with name, age and picture of people in it and on my front page I am able to display the picture with name in a repeater but couldn’t figured out how to display the “[age] + ‘years old’” in the same text box.
Can you help me out with it ?
In advance, thank you very much for your help.
Cheers,
SS
You can use two text box. First is linked dataset the other one static “years old” text.
Right Ramazan, I thought about it but felt it less clean. No technical solution according you ?
thank you
import wixData from 'wix-data';
$w.onReady(function () {
initRepeater()
})
function initRepeater() {
$w('#repeater1').onItemReady(($item, itemData) => { //repeater1 must be replace your repeater id
$item('#text1').text= String(itemData.age) + "years old"; //text1 shows age info
});
}
Thank you very much @ramazanbugdayci02 but not working yet (see below). It is still displaying only the number from database but not the “years old”.
Do I have to keep linked the #text1 to the database with the green bouton (see image)?
Also I feel that this post seems to be related to my problem
Any idea ?
thx again
I think Ramazan’s code should be ok.
Also the suggested infos in the mentioned link are useful.
But the reason for your issue could be the connected dataset trough the property-panel, like you already assumed it. Try to disconnect the dataset and take a look again onto the output.
Thx @russian-dima for your help - I just tried to disconnect (see link button not green anymore) the dataset from my #text1 box but nothing happened
@stillinshows Ok, connect it back to your wished DATABASE.
Check again.
Also show your DATABASE (or an example one) and how you do the connection in your dataset. Make some good screenshots.
@russian-dima sorry for the late reply. Here you will find 2 screenshots (sorry it is in French) of the database and the connection with dataset on the specific text box. Let me know if it is enough for you.
Another point I just thought about is that my text box is linked to a column in my dataset that is set as a “number” data (don’t know if it matters or not)
database:
dataset connection with textbook:
@stillinshows
Normaly all you need is this one…
$w.onReady(function () {
$w('#repeater1').onItemReady(($item, itemData) => {
$item('#text1').text= String(itemData.age) + "years old";
});
});
Delete all your code and start from beginning.
You can connect all your elements to dataset, which you don’t want o manipulate.
But the ones, which you want to manipulate/change, these ones you should modify by code → for example the text-field —> “text1”.
Text1 will be changed by code.
I did just a simple test and everything works just fine for me…look here …
https://www.media-junkie.com/stillin-shows
DB-Settings you will find here on this page… (DB-PRESET-1).
https://www.media-junkie.com/pflegeservice