Hi, I'm trying to link dynamically in a repeater based on the results of a queryReferenced dataset. However, I'm getting an error message that doesn't make sense!
This is my code with the error message:
The same error message comes even outside of the event handler. It just doesn't seem to like the hyphens, but that is the auto-generated field key.
Indeed, this is the correct field key!
Finally, in the console.log(results) of the queryReferenced, it is correct!
How can I fix this? Right now, I am using a workaround where I made another field and simply copy-and-paste the urls from the autogenerated field, but I would like to be able to fix this!!
Thanks
Hey @russian-dima, @ClimateActivist 🖐
The best way is to access the property by using the array method, here's how:
const obj = { 'link-effect-title': 'https://......', name: 'Page Title' }
You can access the properties of the object obj by two methods:
1. The dot annotation method:
// To access the 'name' method obj.name; // Page Title // To access the 'link-effect-title' obj.link-effect-title; // Error
To solve the issue in the first property, we use the array method.
2. The Array method:
// To access the 'name' method obj[name]; // Page Title // To access the 'link-effect-title' obj['link-effect-title']; // 'https://......'
Hope this helps~!
Ahmad
Thank you @Ahmad and @russian-dima! I adapted what Ahmad said, and this is my working code:
wixData.queryReferenced("EffectsCategories", id, "newField", options) .then( (results) => { $w('#repeater1').data = results.items; $w('#repeater2').data = results.items; console.log(results) }) $w("#repeater1").onItemReady( ($item, itemData, index) => { $item("#text66").text = itemData.title $item("#image15").src = itemData.image $item('#text67').text = itemData.seoDescription $item('#button21').link = itemData.url $item("#container2").onClick( (event) => { wixLocation.to(itemData['link-effects-title'])
Thanks for all your help!!
Perhaps it would be a better idea to use UNDERLINES instead of hyphen.
bad idea ---> link-effects-title
good idea --> link_effects_title
better idea ---> linkEffectsTitle