0

I have a <table> that has multiple columns, each having an <input> with a name attribute. To make the name unique, I want to append the row and column index. How do I bind <input name="label['0'][cindex]"> (where cindex is an integer from zero to n-1) in my Vue template?

<th v-for="(col, cindex) in cols" :key="cindex" :col="col">
  <div class="input-group">
    <input type="text" name="label['0'][cindex]" placeholder="Add Label" value="" v-model="column_labels[cindex]" class="form-control label text-center">
    ...
  </div>
</th>
1
  • you should to bind the name attribute using v-bind or : Commented Aug 31, 2019 at 3:55

1 Answer 1

2

You need to use Vue's bindings by prefixing the name with a colon, then construct the name as a string:

:name="'label[\'0\'][' + cindex + ']'"

The entire input field:

<input type="text" :name="'label[\'0\'][' + cindex + ']'" placeholder="Add Label" value="" v-model="column_labels[cindex]" class="form-control label text-center" />
Sign up to request clarification or add additional context in comments.

2 Comments

can i store full tr to database even with new input field? when i store input value get not storing
@samjadps This isn't really a question I can answer here. There is a lot of information I don't have that I would need. I would recommend asking a new question about that specific problem with enough detail to understand what the desired behavior is and what behavior you're seeing instead, and I would suggest including the relevant front-end and back-end code in that new question as well so we can properly examine what your code is doing.

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.