【发布时间】:2020-06-26 15:11:39
【问题描述】:
我需要在 ListView 命令集扩展中实现一个按钮,该按钮仅在用户对列表中的选定项目具有编辑权限时才可见。因此我必须在 onListViewUpdated() 方法中进行异步 api 调用,但我似乎不起作用,因为 onListViewUpdated() 不能用作 aync 函数。有没有人可以解决这个问题?
【问题讨论】:
标签: sharepoint spfx
我需要在 ListView 命令集扩展中实现一个按钮,该按钮仅在用户对列表中的选定项目具有编辑权限时才可见。因此我必须在 onListViewUpdated() 方法中进行异步 api 调用,但我似乎不起作用,因为 onListViewUpdated() 不能用作 aync 函数。有没有人可以解决这个问题?
【问题讨论】:
标签: sharepoint spfx
检查这个thread。
@override
public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
// Get commands
const commandOne: Command = this.tryGetCommand('COMMAND_1');
const commandTwo: Command = this.tryGetCommand('COMMAND_2');
// Command checks
if (commandOne) {
this._hideCommandByPermissionSet(commandOne, SPPermission.editListItems);
}
if (commandTwo) {
this._hideCommandByPermissionSet(commandTwo, SPPermission.approveItems);
}
}
private _hideCommandByPermissionSet(crntCommand: Command, permission: SPPermission) {
if (this.context.pageContext.list.permissions.hasPermission(permission)) {
crntCommand.visible = true;
} else {
crntCommand.visible = false;
}
}
【讨论】: