I have a question about how to retrieve data from an API and display it in a textbox when the edit button on a specific row table is clicked. The data should include its own id along with other details. I apologize for sharing my code in this format, as I am not familiar with formatting it properly and keep encountering errors.
Code excerpt :
data : {
students : []
}
methods: {
async editStudents(edit) {
let id = "621ecc95817b5aeb5783aebe"
let response = await
this.$axios.get(`https://api.qa.sampleapi.com/students/${id}`)
console.log(response.data.data)
}
The above code successfully retrieves the specific item, but I am unsure of how to achieve this using a for loop.
Example code :
editStudent(edit) {
let studentId = id
let response = await
this.$axios.get(`https://api.qa.sampleapi.com/students/${studentId}`)
for(let i = 0; i < this.students.length; i++) {
if(edit.studentId === this.students[i].studentId) {
this.textbox1 = this.students[i].studentId;
}
}
}