javascript - 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');
});
});
解决方案
我相信这可能与事件在 html 绑定上的绑定方式有关。如果像这样使用它们,
data-bind="click: clickHandler()"
它可能会在处理绑定时调用该函数。相反,删除括号,使其指向一个函数而不是调用它。
data-bind="click: clickHandler"
推荐阅读
- docker - 无法在 docker 中运行 jmx 文件
- php - PHP:GoogleSheet 进入数据库,处理空白单元格
- nginx - 使用自定义链接重定向到外部源并跟踪重定向
- c++ - 用给定面值的硬币最少数量来表示金额。贪心问题
- visual-studio - DevOps 从另一个解决方案链接项目依赖关系
- python - 在 on_message 函数中重构和存储来自 mqtt 代理的数据
- post - 在发布后显示状态并在 MVC 视图中保持输入的模型
- scala - 无形。修改标记类型
- sql - 从 2 列计算 2 行之间的 Datediff
- angular - ngx-charts - 水平条形图数据更新时的条形粗细变化