我正在尝试从这里使用 Fluent UI Detailslist 组件, 我只是复制了源代码并拥有一个(较旧的)基于类的组件,称为 DetailsListBasicExample。该组件扩展了 React 组件、花括号和 IDetailsListBasicExampleState:
export class DetailsListBasicExample extends React.Component<{},
IDetailsListBasicExampleState> {
private _selection: Selection;
private _allItems: IDetailsListBasicExampleItem[];
private _columns: IColumn[];
constructor(props:{}) {
super(props);
this._selection = new Selection({
onSelectionChanged: () => this.setState({ selectionDetails: this._getSelectionDetails()
}),
});
// Populate with items for demos.
this._allItems = [];
for (let i = 0; i < 200; i++) {
this._allItems.push({
sortOrder: i,
propertyName: 'Item ' + i,
dbID: i,
});
}
this._columns = [
{ key: 'column1', name: 'Name', fieldName: 'name', minWidth: 100, maxWidth: 200,
isResizable: true },
{ key: 'column2', name: 'Value', fieldName: 'value', minWidth: 100, maxWidth: 200,
isResizable: true },
];
this.state = {
items: this._allItems,
selectionDetails: this._getSelectionDetails(),
};
}
public render(): JSX.Element {
const { items, selectionDetails } = this.state;
return (
<Fabric>
<div className={exampleChildClass}>{selectionDetails}</div>
<Text>
Note: While focusing a row, pressing enter or double clicking will execute
onItemInvoked, which in this
example will show an alert.
</Text>
<Announced message={selectionDetails} />
<TextField
className={exampleChildClass}
label="Filter by name:"
onChange={this._onFilter}
styles={textFieldStyles}
/>
<Announced message={`Number of items after filter applied: ${items.length}.`} />
<MarqueeSelection selection={this._selection}>
<DetailsList
items={items}
columns={this._columns}
setKey="set"
layoutMode={DetailsListLayoutMode.justified}
selection={this._selection}
selectionPreservedOnEmptyClick={true}
ariaLabelForSelectionColumn="Toggle selection"
ariaLabelForSelectAllCheckbox="Toggle selection for all items"
checkButtonAriaLabel="Row checkbox"
onItemInvoked={this._onItemInvoked}
/>
</MarqueeSelection>
</Fabric>
);
}
我不明白的是这一行:
导出类 DetailsListBasicExample 扩展 React.Component<{}, IDetailsListBasicExampleState>
如何将对象数组传递给 DetailsListBasicExample?因为我真的很想填充 Itemslist 但我似乎不知道该怎么做?我试图这样调用组件:
<DetailsListBasicExample props={propertyList}/>
其中 propertyList 是一个对象数组。我还尝试了以下
DetailsListBasicExample IDetailsListBasicExampleState={propertyList}/>
但我得到了著名的 Typescript 错误:
输入'{道具:任何;}' 不可分配给类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<...>'。类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<...>”上不存在属性“props”。
我的理解是属性类型是错误的。但是我怎样才能通过我的项目列表让它起作用呢?
有人有想法吗?我也不明白constructur props:{} 在做什么?