Knockout.js 无法绑定shell.html和shell.js durandal中的单击

Knockout.js 无法绑定shell.html和shell.js durandal中的单击,knockout.js,durandal,Knockout.js,Durandal,这是我的源代码: main.js: requirejs.config({ paths: { 'text': '../Scripts/text', 'transitions': '../Scripts/durandal/transitions', 'durandal': '../Scripts/durandal', 'plugins': '../Scripts/durandal/plugins', 'knock

这是我的源代码:

main.js

requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'transitions': '../Scripts/durandal/transitions',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'knockout': '../Scripts/knockout-2.3.0',
        'jquery': '../Scripts/jquery-1.10.2.min',
        'nivoLightbox': '../Scripts/nivo-lightbox/nivo-lightbox'
    },
    shim: {
        'bootstrap': {
            deps: ['jquery'],
            exports: 'jQuery'
        }
    }
});

define(['durandal/system', 'durandal/app', 'durandal/viewLocator'], function (system, app, viewLocator) {
    //>>excludeStart("build", true);
    system.debug(true);
    //>>excludeEnd("build");
    app.title = 'Cu?i di ku';
    //specify which plugins to install and their configuration
    app.configurePlugins({
        router: true,
        dialog: true,
        widget: {
            kinds: ['expander']
        }
    });
    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.
        app.setRoot('shell', 'entrance');
    });
});
define(['plugins/router', 'durandal/app'], function (router, app) {
    return {
        router: router,
        activate: function () {
            router.map([
                { route: ['', 'home'], title: 'Mới nhất', moduleId: 'viewmodels/stories', nav: true },
                { route: ':storyId/:story', title: ':storyId', moduleId: 'viewmodels/story', nav: true }
            ]).buildNavigationModel();

            return router.activate();
        },
        goHome: function () {
            router.navigate('');
        }
    };
});
在我的
shell.html
中,我有一个菜单:

<div id="top_nav" class="ddsmoothmenu">
    <ul>
        <li data-bind="click: goHome()"><a class="selected"></a></li>
    </ul>
    <br style="clear: left" />
</div>
当页面第一次加载时,它运行到
goHome()
函数(我不知道为什么?)。 当我在菜单中单击时,它不执行此功能?请帮助我解决此问题。

尝试更换:

<li data-bind="click: goHome()"><a class="selected"></a></li>
  • 带:(goHome后的no())

  • 第一次应用绑定时()调用goHome函数

    如果这仍然不能解决问题,那么在加载页面或单击li时,控制台中是否会出现任何错误

    <li data-bind="click: goHome"><a class="selected"></a></li>