【问题标题】:Durandal js, all functions activate at startupDurandal js,所有功能在启动时激活
【发布时间】:2018-12-26 10:16:52
【问题描述】:

我有一个用 Durandal js 和 knockoutJs 包编写的 SPA, 当我运行程序时,所有在启动时触发的function () 函数, 大多数必须由某些动作触发(如点击事件等......) 它工作正常,但我不需要在启动时触发它。 怎么控制?

这是 main.js 的样子:

define(jquery, function () { return jQuery; });
define('knockout', ko);
define(['durandal/system', 'durandal/app', 'durandal/viewLocator', 'bootstrap'], function (system, app, viewLocator) {

app.title = 'Durandal Starter Kit';

app.configurePlugins({
    router: true,
    dialog: true
});

app.start().then(function () {
    //Replace 'viewmodels' in the moduleId with 'views' to locate the view.
    //Look for partial views in a 'views' folder in the root.
    viewLocator.useConvention();

    //Show the app by setting the root view model for our application with a transition.
    app.setRoot('shell', 'entrance');
});

});

【问题讨论】:

  • 触发了什么函数?你能提供一个例子或代码吗?

标签: javascript knockout.js durandal


【解决方案1】:

我相信这可能与事件在 html 绑定上的绑定方式有关。如果它们像这样使用 data-bind="click: clickHandler()" 它可能会在处理绑定时调用该函数。 相反,删除括号,使其指向一个函数而不是调用它。 data-bind="click: clickHandler"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    相关资源
    最近更新 更多