您可以创建一个函数来以编程方式为您生成 nonSelectable 数组。例如
function getNonSelectableRows(rows, userLoginId) {
return rows
.filter((r) => r.createdByID !== userLoginId)
.reduce((acc, r) => {
acc.push(r.fileID);
return acc;
}, []);
}
然后调用 selectRow.nonSelectable 的函数
function App() {
...
// I don't see the user login id in your code.
// Thus I just add it as a constant at the top.
const userLoginId = '200201';
const [files] = useState([
{
fileID: 1,
fileName: "Cardio Care Awareness Month",
createdByID: "100101"
},
{
fileID: 2,
fileName: "MEMO COMPULSORY TO",
createdByID: "100101"
},
{
fileID: 3,
fileName: "MEMO 2021 Covid19 Vaccination Leave",
createdByID: "200201"
},
{
fileID: 4,
fileName: "Human Cell",
createdByID: "200201"
}
]);
const selectRow = {
mode: "checkbox",
// nonSelectable = [1, 2]
nonSelectable: getNonSelectableRows(files, userLoginId),
...