您可以参考以下代码
const MyDetailsList = () => {
const items = [
{ id: 1, name: 'Item 1', color: 'red' },
{ id: 2, name: 'Item 2', color: 'blue' },
{ id: 3, name: 'Item 3', color: 'green' },
];
const columns: IColumn[] = [
{ key: 'id', name: 'ID', fieldName: 'id', minWidth: 50 },
{ key: 'name', name: 'Name', fieldName: 'name', minWidth: 100 },
];
const onRenderRow = (props, defaultRender) => {
const rowClass = mergeStyles({
backgroundColor: props.item.color, // Use the color property of the item to set the background color
});
return <div className={rowClass}>{defaultRender(props)}</div>;
};
return (
<DetailsList
items={items}
columns={columns}
selectionMode={SelectionMode.none}
onRenderRow={onRenderRow}
/>
);
};