我有下面的代码使用 React 框架在 Sharepoint 在线呈现人员选择器。如何添加基本控件,例如标签、文本框和按钮。
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import { Label } from 'office-ui-fabric-react/lib/Label';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { getId } from 'office-ui-fabric-react/lib/Utilities';
export interface IPnPPeoplePickerWebPartProps {
description: string;
}
export default class PnPPeoplePickerWebPart extends
BaseClientSideWebPart<IPnPPeoplePickerWebPartProps> {
public render(): void {
const element: React.ReactElement<IPnPPeoplePickerProps > = React.createElement(
PnPPeoplePicker,
{
description: this.properties.description,
context: this.context
}
);
ReactDom.render(element, this.domElement);
}
这是标签的代码。我只是不知道在哪里插入它。它在渲染方法中不起作用。
export const LabelBasicExample = () => {
// Use getId() to ensure that the ID is unique on the page.
// (It's also okay to use a plain string without getId() and manually ensure uniqueness.)
const textFieldId = getId('anInput');
return (
<div>
<Label>I'm a Label</Label>
<Label disabled={true}>I'm a disabled Label</Label>
<Label required={true}>I'm a required Label</Label>
<Label htmlFor={textFieldId}>A Label for An Input</Label>
<TextField id={textFieldId} />
</div>
);
};
我建议您创建一个新的 React 组件来包装您的组件。另外,你在第一块代码中的 render() 方法有点奇怪……看第二块,没有调用 ReactDom.render。
通常该调用仅在我的 index.tsx 文件上。像这样的东西:
ReactDOM.render(<App />, document.getElementById('root'));
所以在 App.tsx 里面(在组件渲染方法中)我会做这样的事情:
return (
<div>
<mycomponent1/>
<mycomponent2/>
<pnpcomponent/>
... many other components...
</div>)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句