0

how to display value data based on index array. here I make a modal edit data, I have a json like the following

[
    {
        "ID": 3,
        "idusers": 3,
        "skills": "Go",
        "profiency": "Expert",
    },
    {
        "ID": 48,
        "skills": "laravel",
        "profiency": "laravel",
    },
    {
        "ID": 47,
        "skills": "Vue",
        "profiency": "Expert",
    }
]

table data that I display

<tr v-for="(skill, index) in getSkills" :key="skill.ID">
    <td>{{ index + 1 }}</td>
    <td>{{ skill.skills }}</td>
    <td>{{ skill.profiency }}</td>
    <td class="text-xs-center">
    <td><div v-if="editBtn == true">
        <v-btn class="mr-3" x-small fab v-on:click="handleEdit(item,index)" color="primary"><v-icon>mdi-cancel</v-icon></v-btn>
    </td>
</tr>

and this my modal edit

 <v-dialog v-model="skillForm" width="500">
        <v-container>
            <v-text-field outlined dense>
                {{profiency}}
            </v-text-field>
        </v-container>
</v-dialog>

my method

export default {
  name: "Skills",
  data: function() {
    return {
      formAddSkills: "",
      skillForm: false,
      editBtn: "",
      skills: {
        skills: "",
        profiency: "",
      },
    };
  },
  computed: {
    ...mapState({ getSkills: (state) => state.resume.Skills }),
    dataSkills() {
      return this.skills;
    },
  },
  methods: {
    handleEdit(item, index) {
      this.skillForm = true;
      this.editBtn = true;
      this.profiency = item.profiency
      // console.log(item)
      console.log(index)
    },
  }
}

the question is how to display data based on ID, when I click the edit button it appears and enters the text field form

1
  • you should have passed skill as 1st parameter instead of item. v-on:click="handleEdit(skill,index)" Commented Feb 2, 2021 at 4:33

1 Answer 1

1
  1. Pass skill from your method as a parameter @click="handleEdit(skill,index)
  2. Then declare a variable, currentObject, and then equate it this.currentObject = skill inside the method.
  3. Then you can access currentObject.id via the v-model binded to your text field.
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.