在document.ready

时间:2016-09-09 04:02:54

标签: aurelia

我遇到了aurelia和物化桥下拉列表的问题。该桥调用jquery元素上的函数以启用materialize下拉小部件。同时,实现调用相同的方法在文档$('.dropdown-button').dropdown();

中的所有下拉列表上启用窗口小部件

当我使用aurelia-bundler捆绑缩小代码时出现问题。自定义控件上的Attached方法比document.ready代码更早执行。这导致下拉列表忽略选项。

在这种情况下,有没有办法强制执行执行顺序?

1 个答案:

答案 0 :(得分:3)

正如我们在桥梁作者@Thanood中发现的那样,解决方案是延迟设置aurelia root,直到加载文档。这会强制执行正确的方法调用命令

export async function configure(aurelia: au.Aurelia) {
    aurelia
        .use
        .standardConfiguration()
        .developmentLogging()
        .plugin("aurelia-materialize-bridge", bridge => bridge.useAll());

    await aurelia.start();
    // this delays loading the root until the document is ready to solve Materialize issue when widgets are initialised twice
    await new Promise(resolve => $(document).ready(() => resolve()));
    aurelia.setRoot("views/root");
}
相关问题