【问题标题】:Import variables into aurelia-dialog view-model or view将变量导入 aurelia-dialog 视图模型或视图
【发布时间】:2017-04-08 03:57:52
【问题描述】:

有没有办法将额外的变量/数据从对话服务导入控制器?

例如,我的应用视图形式有一系列可能的选项。我通过 API 从服务器获取数据。

我想使用 aurelia-dialog 编辑条目,并且不想再次获取数据以避免在我的应用中产生不必要的流量。

如何将数组另外传递给模型。将它们全部打包在一个对象中并在控制器中解包? 据我所知,控制器的激活方法只需要一个参数,不是吗?

谢谢

【问题讨论】:

    标签: aurelia aurelia-dialog


    【解决方案1】:

    存储库中的示例不正是您正在寻找的吗? person 属性通过 settings 对象 (model: this.person) 传递给对话服务。这可能是您从服务器获取的数据。正如您所提到的,您当然也可以将多个对象添加到模型中,这将在您的对话框虚拟机的 activate() 方法中可用。

    import {EditPerson} from './edit-person';
    import {DialogService} from 'aurelia-dialog';
    export class Welcome {
      static inject = [DialogService];
      constructor(dialogService) {
        this.dialogService = dialogService;
      }
      person = { firstName: 'Wade', middleName: 'Owen', lastName: 'Watts' };
      submit(){
        this.dialogService.open({ viewModel: EditPerson, model: this.person}).then(response => {
          if (!response.wasCancelled) {
            console.log('good - ', response.output);
          } else {
            console.log('bad');
          }
          console.log(response.output);
        });
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2018-10-15
      • 2017-06-24
      • 2016-01-23
      相关资源
      最近更新 更多