首页 > 解决方案 > Durandal js,所有功能在启动时激活

问题描述

我有一个用 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');
});

});

标签: javascriptknockout.jsdurandal

解决方案


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


推荐阅读