Simple list challenge which I cannot figure out

I have a relative simple challenge, which I cannot to figure out.

I have Table1 with two columms: id, values

Table1 is listed on the page with a repeat:

<div id="repeat1" is="dmx-repeat" dmx-bind:repeat="get_values.data.query1"> 
<button>{{Values}}</button>

If a user clicks on one of the buttons, it needs to be recorded in Table2 with the structure: id, answer

I do this by adding the following to the button:
dmx-on:click="add_answer.load({id:$index,answer:Values})

So far so good.

Now the tricky part:

When the user clicks the same button again, the entry need to be deleted, by loading this:
del_answer.load({id:$index,answer:Values})

I thought a ternary function would be suitable, but I cannot figure out the correct code.
Especially how to identify the correct ID.
Anyone have some suggestion how to do this?


Note: This is a simplified example, in my table has a bit more detail and I have also added class change to highlight which button is selected, etc., but I left this out to focus on to the core of the challenge

Community Page
Last updated: