首页 > 解决方案 > Office-UI-fabric DocumentCardActions 不起作用

问题描述

我正在为我的应用程序使用 office fabric ui DocumentCardActions。但是当我单击操作按钮时它不起作用

<DocumentCard styles={cardStyles} >
   <div className={conversationTileClass}>
      <DocumentCardTitle
          title={selectedInvoice.name}
            shouldTruncate/>
              <DocumentCardTitle title={selectedInvoice.status}
                         shouldTruncate showAsSecondaryTitle/>
             <DocumentCardStatus statusIcon="attach"  />
     </div>
          <DocumentCardActions
                   actions={[
                     {
                        iconProps: { iconName: 'CodeEdit' },
                     onClick:handleEdit(selectedInvoice),
                       ariaLabel: 'share action'
                      },
                    {
                iconProps: { iconName: 'Cancel' },
                 onClick: handleDelete(selectedInvoice.id),
                   ariaLabel: 'pin action'
                    },
                   ]}
                />

我的功能是

const handleDelete =(id)=> {
    console.log(id);
};
function handleEdit (item) {
    console.log(item);
};

标签: reactjsreact-hooksoffice-ui-fabric

解决方案


这是带有工作操作按钮的 codepen:https ://codepen.io/vitalius1/pen/pXvyog

<DocumentCardActions
      actions={[
        {
          iconProps: { iconName: 'Share' },
          onClick: this._onClick.bind(this, 'share'),
          ariaLabel: 'share action'
        },
        {
          iconProps: { iconName: 'Pin' },
          onClick: this._onClick.bind(this, 'pin'),
          ariaLabel: 'pin action'
        },
        {
          iconProps: { iconName: 'Ringer' },
          onClick: this._onClick.bind(this, 'notifications'),
          ariaLabel: 'notifications action'
        }
      ]}
      views={432}
/>

private _onClick(action: string, ev:React.SyntheticEvent<HTMLElement>):void {
    alert(`You clicked the ${action} action`);
    ev.stopPropagation();
    ev.preventDefault();
}

它是打字稿,但我可以想象你可以剥离大部分内容并在需要时将其设为 JS。


推荐阅读