简体   繁体   English

在Aurelia对话框中,如何为viewModel创建路由?

[英]In an Aurelia Dialog, how to create routes for the viewModel?

When opening an Aurelia Dialog you usually pass it a viewModel. 打开Aurelia对话框时,通常会向其传递一个viewModel。

This is how I'm currently doing this but it would be better if the path wasn't hard-coded here. 这就是我目前正在这样做的方式,但如果此处未对路径进行硬编码,那会更好。

            let lookupResponse = await this.dialogService.open(
            {
                model:
                {
                    configuration: this.LookupConfiguration
                    caption: 'Select an item'
                },
                viewModel: 'App/Components/Lookup/LookupDialog'
            });

I'd rather be able to reference the viewModel path like a route 我宁愿能够像路由一样引用viewModel路径

            let lookupResponse = await this.dialogService.open(
            {
                model:
                {
                    configuration: this.LookupConfiguration
                    caption: 'Select an item'
                },
                viewModel: App.routes.components.lookupdialog
            });

If you just add a Routes.js for the components and try to use it you get this error: 如果仅为组件添加Routes.js并尝试使用它,则会出现此错误:

Uncaught (in promise) Error: Cannot determine default view strategy for object. 未捕获(承诺)错误:无法确定对象的默认视图策略。

So what needs to be added for this to work? 那么,需要添加什么才能使其起作用? A custom view strategy of some kind? 某种自定义视图策略?

You can import the dialogs into your class and use them like this: 您可以import对话框导入到您的班级中,并像下面这样使用它们:

import { LookupDialog } from "app/components/lookup/lookup-dialog.ts";

export class Foo {
  bar() {
    let lookupResponse = await this.dialogService.open(
       {
         model:
         {
           configuration: this.LookupConfiguration
           caption: 'Select an item'
         },
         viewModel: LookupDialog
       });
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM