簡體   English   中英

使用Aurelia動態組成視圖

[英]Dynamically composing a view with Aurelia

我試圖動態組成視圖,但在運行時出現Error: Unable to find module with ID: app/components/customers/customer-type-view-converter.html. 我正在使用webpack。

這是我正在使用的視圖轉換器

 import {PLATFORM} from 'aurelia-framework';

export class CustomerTypeViewConverter {
    toView(type: string) {
     return  type  == 'LEGAL' ? PLATFORM.moduleName("createLEGALcustomer.html") : PLATFORM.moduleName("createNATURALcustomer.html")
    }
  }

這是調用轉換器的模板

<template>

    <require from="./customer-type-view-converter"></require>
    <ux-dialog style="min-width:500px">

        <ux-dialog-header>
            <h1>Create Customer</h1>
        </ux-dialog-header>

        <ux-dialog-body>
            <form class="form-horizontal">

                <div class="form-group">

                    <label for="name" class="col-sm-4 control-label">Customer Type:</label>
                    <div class="col-sm-8">
                        <select value.bind="customer.customerType">
                            <option value="NATURAL">Person</option>
                            <option value="LEGAL">Company or Organisation</option>
                        </select>

                    </div>

                </div>

                <compose view.bind="customer.customerType | customerTypeView"></compose>

            </form>

        </ux-dialog-body>

        <ux-dialog-footer>
            <button click.trigger="controller.cancel()">Cancel</button>
            <button click.trigger="submit()">Ok</button>
        </ux-dialog-footer>

    </ux-dialog>

</template>

這里有兩個問題。 首先。 該類名稱應該是CustomerTypeView Value Converter,以便Aurelia將其重新定義為不需要視圖的特殊類。

並且在Value Converter本身中,html文件應該以./為前綴,因此webpack可以找到它們

下面的更新值轉換器

 import {PLATFORM } from 'aurelia-framework';

export class CustomerTypeViewValueConverter  {
    toView(type: string) {
     return  type  == 'LEGAL' ? PLATFORM.moduleName("./createLEGALcustomer.html") : PLATFORM.moduleName("./createNATURALcustomer.html")
    }
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM