首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExtReact中传递参数的错误

ExtReact中传递参数的错误
EN

Stack Overflow用户
提问于 2018-03-08 15:49:11
回答 1查看 36关注 0票数 0

在传递属性的代码的这一部分中,可以在页面上呈现一次属性:

代码语言:javascript
复制
constructor(props){
    super(props);
    this.state = {
        idOfPortletLocation: props.portletlocationid
    };
}

render() { 



    const text = (
        <div>
            {this.props.text.description}
            {this.state.idOfPortletLocation}
        </div>
    );

……

正如你从截图中看到的:

证明

但是,代码的这一部分不识别属性idOfPortletLocation:

代码语言:javascript
复制
<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> 

以及:

代码语言:javascript
复制
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");
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-08 16:02:33

处理程序:(e) => this.toolHandler(e,this.state.idOfPortletLocation) //这里只传递两个参数,idOfPorletLocation作为第二个参数//但在toolHandler中有三个参数,idOfPorletLocation作为第三个参数,但作为第二个参数被传递。

所以正确的功能应该是-

代码语言:javascript
复制
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");
}

让我知道它是否对你有用)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49177155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档