Hi everyone.
I am trying to change the contents of a non connected text element in a repeater with data from a 'field' that I want to be able to change depending of the value of dropdown .
I have never coded before so any help will be appreciated . This is where i am so far:
//////////////////////////////////////////////////////////////////////////
//pic the days field (str) based on number of #dropdown5// /////////////////////////////////////////////////////////////////////////// export function button4_click() { search(); } function search() { wixData.query("days") .eq("int", $w("#dropdown5").value) .find() .then( (results) => { let items = results.items; let days = items[0].str; console.log(days); /////////////////////////// Ok till here /////////////////// $w('#repeater1').onItemReady( ($item, itemData, index) => { $item("#text51").text = itemData.days; console.log(); }); }); }
I want to use the 'days' variable from "let days = items[0].str; "
witch is a string 'one' 'two' 'three' ....
and use it on " $item("#text51").text = itemData.days;".
If i put 'two' for example " $item("#text51").text = itemData.two;" every thing works ok
but i cant use the variable 'days'.
If anyone can point me in the right direction that would be great .
Thank you
I think with data hooks it can be done ,but that involves a lot more reading !!
It is vary confusing at the moment.
Is there a article somewhere that explains things in more detail for newbies like me?
Thanks
To set the Repeater to the results of a query, you should use the .data property of the Repeater. Something like this:
let items = results.items; $w("#repeater1").data = items;
The Repeater.onItemReady() function, which should be set in the page's onReady() function, is an event handler, which is called when the Repeater items are created - that is, after the repeater's data property is set. The page's onReady() function with the the Repeater's onItemReady() function would look something like this:
$w.onReady(function () { $w('#repeater1').onItemReady(($item, itemData, index) => { $item("#text51").text = itemData.two; }); });
I hope this helps,
Yisrael
Hi @ioannis,
The reason it was OK until the onItemReady() is because onItemReady() is an event handler for the Repeater that gets called automatically when the Repeater is creating the Repeater items. As state in the $w.Repeater.onItemReady() API documentation: Sets the function that runs when a new repeated item is created.
Further, input components (e.g. Dropdown) cannot be added to a Repeater item, only display components.
We appreciate your interest in really getting the most out of Wix Code and how much you want to learn. You will need to familiarize yourself with basic coding concepts to accomplish what you want. There are a wealth of Javascript coding sites which will help you learn Javascript from basic to advanced - Javascript.info is a good one. The Wix Code Resources page provides tutorials, examples, and articles on getting the most out of Wix Code. We are happy to get you pointed in the right direction, but you’ll need to take it from there. As questions or difficulties arise, we are here to help.
Have fun,
Yisrael