This is second part in the series to make use of getters and setters in an AlpineJS object, that converts INR to USD.
Well, only a setter has been used here where a function call is made to the setter priceInINR
when the textbox of the USD value changes. The setter changes the value of the product's (which is an argument to priceInINR
) price_INR
value.
x-on:input="$
store.global
_data.priceInINR = product"
And the setter :
set priceInINR(p)
{
const product = this.products.find(product => product.name === p.name);
product.price_INR = p.price_USD * 83;
},
Here's the full source code.
PS: 1 USD = 83 INR as of 17th February 2024.
Here's a more interactive example / demo : https://anjanesh.s3.amazonaws.com/demo/alpine/alpine-auto-update-variable-method-1.html