Nathan
Nathan

Reputation: 125

How to transcribe Vue associative array into HTML form input values

I have an HTML form, which used to have input values based on a Vue array like so:

// Vue Var
var postIDarr = [postID, postID, etc., etc.];
// HTML
<input v-for="(id, index) in postIDarr" type="hidden" name="postIDArr[]" :key="index" :value="id">

This worked fine for a while, but now I want to make the array an associative array, encoding both the postID and the userID for processing on the backend. The array in Vue has the structure as follows;

var postIDarr = {
    userID: postID,
};
// These are placeholders obviously

How would I be able to encode both of these values into the HTML form?

Wasn't entirely sure how to write this question without being repetitive, if you need any more information please let me know.

Upvotes: 0

Views: 63

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

if you have an object like :

var postIDarr = {
    userID: postID,
}

and you want want render it using v-for by showing the key and value, so you could do it like :

 v-for="(id,key, index) in postIDarr" 

id refers to postID

key refers to userID

Upvotes: 1

Related Questions