5

I have a dynamic table rendering where columns and rows of the table are rendered dynamically.

So here I have two sibling <td> elements in each row:

<td :key="`td3-${index}`" :id="`show_${key}`" v-show="`show_${key}`">
  <input type="text" :v-model="key" :name="key" :value="entry[key]" />
</td>
<td :key="`td4-${index}`">
  <a href="#" @click="showField(key)">Edit</a>
</td>

In the onclick event of the link in the second <td> I have to show and hide the first <td> element. Since it's dynamic I will have multiple rows. So I declared a dynamic boolean in my data to show and hide the specific <td> based on the click of another <td> in the same row.

v-show="`show_${key}`" - this is show property with dynamic key

  show_firstname: false,
  show_lastname: false,
  show_email: false,
  show_orgname: false

I created separate boolean elements for every <td> in each row.

Table structure

But whenever I change the value of v-show property with the on click of second <td> element it's not making any difference. So I could not show or hide the <td>. Maybe v-show takes "`show_${key}`" as a string value not replacing true or false correctly. Can someone help me how can I achieve this?

1 Answer 1

2

Why don't you try organising the show_ in an object instead of a flat list of properties?

https://codesandbox.io/embed/vue-template-csncc?fontsize=14&hidenavigation=1&theme=dark

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.