【问题标题】:In an Aurelia Dialog, how to create routes for the viewModel?在 Aurelia Dialog 中,如何为 viewModel 创建路由?
【发布时间】:2017-11-16 22:09:36
【问题描述】:

当打开 Aurelia 对话框时,您通常会向它传递一个 viewModel。

这就是我目前的做法,但如果路径没有在这里硬编码会更好。

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

我宁愿能够像路由一样引用 viewModel 路径

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

如果你只是为组件添加一个 Routes.js 并尝试使用它,你会得到这个错误:

未捕获(承诺中)错误:无法确定默认视图策略 对象。

那么需要添加什么才能使其正常工作?某种自定义视图策略?

【问题讨论】:

    标签: javascript aurelia


    【解决方案1】:

    您可以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
           });
      }
    }
    

    【讨论】:

    • 当我以这种方式尝试时,我得到了这个错误:未捕获(承诺)错误:找不到模块'./604.html'
    • 我看不到那个错误来自哪里,因为我看不到你在哪里导入了那个文件:)
    • 可能是版本问题。我有一个用 webpack 1.x 构建的旧版本和一个用 webpack 3.x 构建的新版本。使用较新的版本,导入工作正常。它只是对旧的废话。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 2020-08-05
    相关资源
    最近更新 更多