【问题标题】:Office Fabric UI - onClick IconButton does not working when I Package-SolutionOffice Fabric UI - 当我打包时,onClick IconButton 不起作用
【发布时间】:2018-04-16 17:00:21
【问题描述】:

我有下表:

行以动态方式绘制,还有用于删除每一行的按钮。

<span className="ms-Table-cell">
  <div>
    <IconButton
      onClick= { this._removeItemFromDetail }
      id={ detail.Id.toString() }
      iconProps={ { iconName: 'Cancel' } }
      title='Delete' />
  </div>  
</span>

private _removeItemFromDetail(e) {
    console.log("e.target",e.target);
}

问题是每次我点击控制台中的删除按钮时都会显示:

所以,我无法访问 Button Id 属性,但这只会在我发布 Webpart 时发生。 有谁知道如何解决?

谢谢!

【问题讨论】:

    标签: button office-ui-fabric spfx


    【解决方案1】:

    在 IconButton 的 onClick 中,您可以编写以下内容;

    onClick={() => {this._removeItemFromDetail(detail.Id)}}
    

    这应该允许您接受 ID 作为参数。如果您仍然需要 _removeItemFromDetail 方法中的“事件”,您可以按如下方式添加它;

    onClick={(event) => {this._removeItemFromDetail(event, detail.Id)}}
    

    这意味着你的方法看起来像这样;

    private _removeItemFromDetail(event, itemId) {
        console.log("itemId: " + itemId); 
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 2017-06-05
      • 2021-04-02
      • 2020-05-29
      • 2020-09-13
      • 2017-07-09
      相关资源
      最近更新 更多