Today, I'm facing the challenge of retrieving JavaScript index based on a specific data ID that I have selected.
I am referring to the documentation at , where they suggest using something like: checkedRows: [data[1], data[3]]
to mark a particular row in a table as checked.
My goal is to mark the rows in the table according to the response received from my web API.
Here is a snippet of the sample response data:
response.data.checkedRows // contains [{id: 1234}, {id: 83412}]
Additionally, here is an excerpt of the sample data from the table:
const data = [{
id: 1234,
name: 'Jojo'
},{
id: 43221,
name: 'Jeff'
},{
id: 83412,
name: 'Kacey'
}]
Essentially, I need a dynamic solution similar to this: checkedRows: [data[0], data[2]]
as it aligns with the IDs present in response.data.checkedRows
.
Thus far, I have attempted to utilize the forEach
method:
let selectedIndex = [];
response.data.checkedRows.forEach((d) => {
this.data.forEach((e) => {
if (d.id=== e.id) {
// aiming for a dynamic outcome based on the response.data.checkedRows
this.checkedRows = [data[0], data[2]]
}
});
});
I am currently stuck as I cannot determine how to match the selected indexes with the checkedRows from the response. Any insights would be greatly appreciated!