在传递属性的代码的这一部分中,可以在页面上呈现一次属性:
constructor(props){
super(props);
this.state = {
idOfPortletLocation: props.portletlocationid
};
}
render() {
const text = (
<div>
{this.props.text.description}
{this.state.idOfPortletLocation}
</div>
);……
正如你从截图中看到的:
但是,代码的这一部分不识别属性idOfPortletLocation:
<Container padding={10} className="containerOfPanel" flex = {1}/*style={{display: 'inline-block', position: 'absolute'}}*/>
<Panel
ref={panel => this.panel = panel}
title= {this.props.text.title}
/*height= {this.props.height}*/
/*minHeight = {this.props.height}*/
tools={[
{type: 'minimize', handler: this.toolHandler},
{type: 'maximize', handler: (e) => this.toolHandler(e, this.state.idOfPortletLocation) },
{type: 'close', handler: this.toolHandler }
]}
resizable={{
edges: "all",
}}
bodyPadding={10}
>
{text}
</Panel>
</Container>
以及:
toolHandler(owner, tool, idOfPortletLocation) {
console.log(tool.config.type);
console.log(idOfPortletLocation); /* Here it is not recognized */
if(tool.config.type.valueOf() == "close"){
console.log("passed");
}
}发布于 2018-03-08 16:02:33
处理程序:(e) => this.toolHandler(e,this.state.idOfPortletLocation) //这里只传递两个参数,idOfPorletLocation作为第二个参数//但在toolHandler中有三个参数,idOfPorletLocation作为第三个参数,但作为第二个参数被传递。
所以正确的功能应该是-
toolHandler(tool, idOfPortletLocation) {
console.log(tool.config.type);
console.log(idOfPortletLocation); /* Here it is now recognized */
if(tool.config.type.valueOf() == "close"){
console.log("passed");
}让我知道它是否对你有用)
https://stackoverflow.com/questions/49177155
复制相似问题