我想我已经做到了。以下是我正在做的事情。下面是我的组件,我在父页。
主页面组件
import * as React from 'react';
import { DetailsList, IColumn, Link, Fabric } from 'office-ui-fabric-react';
import { IResultListProps } from './IResultListProps';
export class ResultList extends React.Component<IResultListProps, {}> {
constructor(props: IResultListProps) {
super(props);
}
public render(): React.ReactElement<IResultListProps> {
return (
<DetailsList items={this.props.items} columns={this.getColumns()} />
);
}
private getColumns(): IColumn[] {
return [
{
key: 'name',
name: 'name',
fieldName: 'name',
minWidth: 100,
maxWidth: 120,
isResizable: true,onRender: (item) => <a target="_blank" href={`https://localhost:4321/temp/workbench.html?selectedName=${item.name}`}>{item.name}</a>
}
];
}
}
这里的本地页面链接只是用于测试,您应该将其更改为详细信息页面链接。
子/详细页
在我的详细页web部件的typescript文件。我已经进口了
UrlQueryParameterCollection
import { UrlQueryParameterCollection } from '@microsoft/sp-core-library';
onInit
我得到的值如下。
protected onInit(): Promise<void> {
return super.onInit().then(() => {
let queryParameters = new UrlQueryParameterCollection(window.location.href);
let name = queryParameters.getValue("name");
alert(name);
})
}
从这里我可以开始编写api来获取所需的数据并设计我的页面。