在传递属性的代码的这一部分很好,它们在页面上呈现一次:
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");
}
}
答案 0 :(得分:0)
处理程序:(e)=&gt; 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");
}
让我知道它是否适合你)