【问题标题】:onClick / onItemClick JSX Syntax React + Office UI FabriconClick / onItemClick JSX 语法 React + Office UI Fabric
【发布时间】:2018-10-31 06:29:19
【问题描述】:
          <div>
            <CommandBar 
            areNamesVisible={false} areIconsVisible={true}
            items={[
            { name:"James Towns", className:"noHoverEffect", },
            { key:"Info", icon:"Contact", onItemClick={this.handlePanel} },
            { key:"Export", icon:"Download" }
            ]}       />
          </div>  

我正在使用来自 Office UI Fabric 的组件 CommandBar,并且我已经根据需要创建了内容,如附图所示:

接下来我要实现的是将onClickonItemClick 附加到其中一个项目。

不确定这完全是如何工作的,而且 JSX 语法似乎也不是直截了当的。

我的功能是handlePanel感谢任何帮助,在网上查了几天找不到预先存在的问题。

谢谢

【问题讨论】:

    标签: javascript reactjs onclick jsx onitemclick


    【解决方案1】:

    在构造函数中绑定你的函数名或使用箭头函数。 下面是在构造函数中使用绑定的示例

    1. 首先在构造函数中绑定你的函数,如下所示

      this.handlePanel = this.handlePanel.bind(this);

    2. 第二次调用组件内的函数为

      手柄面板(){ // 这里写代码 }

    【讨论】:

    • 完美。 handlePanel = () =&gt; { this.refs.customPanel._showPanel(); this.handlePanel = this.handlePanel.bind(this); } then `key:"Info", icon:"Contact", onClick:this.handlePanel`在JSX中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2021-04-02
    • 1970-01-01
    • 2020-09-13
    • 2020-10-10
    相关资源
    最近更新 更多