代码之家  ›  专栏  ›  技术社区  ›  ConductedClever

确定是否在提示中作为对话框打开

  •  0
  • ConductedClever  · 技术社区  · 5 年前

    我正在开发一个aurelia应用程序。我有一个组件(这是一个完整的页面组件,是可导航的),而且在另一个页面中,我想使用这个组件作为提示,让用户从该页面中进行选择。所以我写了下面的代码来打开它:

    selectTaskFromTree(callbackOrSuccess, failure) {
        const dialog = this.dialogService
          .open({ viewModel: PLATFORM.moduleName('features/view/tree/tree'), model: {}, lock: false });
    
        if (callbackOrSuccess) {
          if (failure) {
            dialog.whenClosed(response => {
              if (!response.wasCancelled) {
                callbackOrSuccess(response.output);
              } else {
                failure(response);
              }
            });
          }
          else{
            dialog.whenClosed(callbackOrSuccess);
          }
          return;
        }
        else{
          return dialog;
        }
      }
    

    所以组件 Tree 现在已成功加载并显示。现在的问题是如何确定 TreeComponent

    我的想法是传递一个任意参数给它,如果参数为真,状态为dialog,否则不是dialog:

      const dialog = this.dialogService
          .open({ viewModel: PLATFORM.moduleName('features/view/tree/tree'), model: {isDialog: true}, lock: false });
    

    但我想也许还有更好的方法。例如,从DialogService询问我是否是一个对话框。那么其他的解决方案是什么,哪一个更好呢?

    0 回复  |  直到 5 年前
        1
  •  1
  •   Henrik Erstad    5 年前

    DialogService

    this.dialogService.hasOpenDialog
    this.dialogService.hasActiveDialog
    

    遗憾的是,这不能告诉你 哪一个 对话框已打开。我认为您将param传递给模型的想法是一种同样有效的方法。

        2
  •  1
  •   ConductedClever    5 年前

    我已经考虑过不同的解决方案,我正在寻求保持低耦合和防止新参数的定义。所以我写了下面的代码,我想知道这个组件是否作为对话框打开:

      attached() {
        this._isDialog = Boolean(this.dialogController.settings);
      }