0👍
Currently you just provide the element with index
0
in your code, as seen in phaseData[0].project_id
. You need to provide the index
to the function which opens your form
.
I don´t see that you posted your code of the table
, but it simply would be like callFormDialogFunction(index)
and passing that index into the form, then using it like phaseData[index].project_id
.
EDIT: Changes according to your full provided code
You are calling @click="editPhaseData(index)"
but you have two parameters in your function:
editPhaseData: function (id, index) {
this.editIndex = index;
this.showPhaseModal = true;
this.axios
.get("http://45.114.85.18:8099/api/project/phase?project_id=" + id, {
headers: {
Authorization: "Bearer " + localStorage.getItem("access_token"),
},
})
.then((res) => {
this.phaseData = res.data.data;
this.showPhase = res.data.data;
});
}
In this case this.editIndex
will be undefined, as there is no second parameter. Example:
editPhaseData(index) // index is the first parameter
editPhaseData: function (id, index) {...} // id is the first parameter, so id is what you passed as index. The second one, called index, is undefined.
In your case it looks like data.id
in your loop provides the id of the so called phase. So you need to call @click="editPhaseData(data.id, index)"
. Then in editPhaseData: function (id, index) {...}
the id
parameter will be the data.id
and index
parameter will be index
.
But now, as this.editIndex
is the index of the phase you want to edit, you need to change phaseData[index].project_id
to phaseData[editIndex].project_id
.
EDIT 2: Your error according project_id
As you not provided the structure of your data, I can´t tell what key project_id
should be. So on phaseData[editIndex].project_id
you need project_id
to the key, which provides the key of your id. If the key is id
, it would be phaseData[editIndex].id
.