You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过IHostPageLayoutService编程关闭Azure DevOps对话框?

如何编程关闭Azure DevOps扩展中通过IHostPageLayoutService打开的对话框?

问题描述

我正在开发Azure DevOps扩展,使用以下代码通过IHostPageLayoutService打开了对话框:

const dialogSVC: IHostPageLayoutService = await getService<IHostPageLayoutService>(CommonServiceIds.HostPageLayoutService);
dialogSVC.openMessageDialog(message, {lightDismiss: false, showCancel: _showCancel, title: "Codespaces Extension"});

请问是否有可用的方法来编程关闭已打开的对话框?

解决方案

  • openMessageDialog方法会返回一个包含对话框实例的IPromise<IDialogResult>对象,你可以调用该对象的close()方法来编程关闭对话框。
  • 示例代码:
    const dialogSVC: IHostPageLayoutService = await getService<IHostPageLayoutService>(CommonServiceIds.HostPageLayoutService);
    // 保存对话框的Promise实例
    const dialogInstance = dialogSVC.openMessageDialog(message, {lightDismiss: false, showCancel: _showCancel, title: "Codespaces Extension"});
    
    // 在需要关闭对话框的逻辑处执行
    dialogInstance.close();
    
  • 注意:调用close()方法会直接触发对话框关闭,无需等待用户交互,适用于需要自动关闭对话框的场景(比如异步操作完成后)。

内容的提问来源于stack exchange,提问作者Alekhya Yalla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 05:42:08