1
I have a Datatable table being powered by Alpinejs:
<template x-for="user in users" :key="user.Id">
On x-for, I have the user.id value that I can list in a SPAN field, with the x-text instruction:
<span id="user.Id" class="text-gray-700 px-6 py-3 flex items-center" x-text="user.Id"></span>
I need to concatenate the user value. Id at the end of my HREF property, which will call a route in the backend for inactivation of a record:
Directly, trying to define the HREF + user.id property, it didn’t work, so I thought the following:
<script>
var uid = document.getElementById("user.Id");
console.log('Valor de uid: ' + uid.InnerText);
var link = document.getElementById("link");
link.setAttribute('href', 'http://api-paulinhomonteiro-com.umbler.net/cli/delete/<%= token %>/' + uid.innertText)
</script>
It worked very well setting the property dynamically but the variable arrives as Undefined.
How could I solve this? I just discovered Alpinejs and I can’t move on.
P.S. Dear friends, despite the great help of friend #Leandrade, I still can not solve. The point is: how to use the contents of the x-text variable, concatenated with HREF?
In that
log
the value of uid.Innertext comes as what?– LeAndrade
Hello Leandrade, thank you for responding. The amount arrives as UNDEFINED.
– Paulo Monteiro
Yes why did you put Innertext with uppercase i.
– LeAndrade
Dear Leandrade... YOU ARE ABSOLUTELY RIGHT. What makes the lack of attention... Thank you so much for the answer. Problem solved here! Big hug and thanks.
– Paulo Monteiro
For nothing, friend, success there!
– LeAndrade
Dear friends, despite the great help of friend #Leandrade, I still can not solve. The point is: how to use the contents of the x-text variable, concatenated with HREF?
– Paulo Monteiro
To everyone who has helped in any way, especially @Leandrare, thank you very much! Solution found here: https://stackoverflow.com/questions/61902261/problem-to-concatenate-alpinejs-x-text-and-href-property/61913267#61913267 If anyone needs any help with Alpinejs or Tailwind, I already have a little luggage and recommend the tools too much. Big hug!
– Paulo Monteiro