Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ko.bindingHandler与Durandal之间的问题_Javascript_Knockout.js_Single Page Application_Durandal - Fatal编程技术网

Javascript ko.bindingHandler与Durandal之间的问题

Javascript ko.bindingHandler与Durandal之间的问题,javascript,knockout.js,single-page-application,durandal,Javascript,Knockout.js,Single Page Application,Durandal,我遇到了一个问题,让敲除绑定处理程序与Durandal一起工作。我目前有一个名为bindings.js的文件,我正在通过RequireJS将其加载到名为todo.js的viewmodel中。出于某种原因,绑定处理程序似乎没有连接。添加待办事项并在键盘上按回车键后,Enter键不起作用。谢谢你的帮助。该项目的代码位于。随便用叉子叉吧。还值得注意的是,大多数淘汰代码都来自该项目 下面是bindings.js文件的一个片段。文件位于 下面是连接bindingHandler的HTML代码片段。存档在 再

我遇到了一个问题,让敲除绑定处理程序与Durandal一起工作。我目前有一个名为bindings.js的文件,我正在通过RequireJS将其加载到名为todo.js的viewmodel中。出于某种原因,绑定处理程序似乎没有连接。添加待办事项并在键盘上按回车键后,Enter键不起作用。谢谢你的帮助。该项目的代码位于。随便用叉子叉吧。还值得注意的是,大多数淘汰代码都来自该项目

下面是bindings.js文件的一个片段。文件位于

下面是连接bindingHandler的HTML代码片段。存档在


再次感谢您的时间。

Binding.js不是AMD格式,所以我建议您在加载knockout之后加载它,不要将其声明为依赖项。
scripts/native
是否为AMD格式

define(
    [
    //'knockout', // Durandal expects knockout and $ loaded via script tag,
    //'jquery',   // no need to define them as deps as well
    'durandal/app', 
    'durandal/system', 
    'scripts/dataservice', 
    'scripts/model',
    'scripts/config',
     //'scripts/bindings',
    'scripts/native' // remove if not in AMD format
    ], 
    function(app, system, dataservice, model, config) {
    'use strict';

抢手货新手犯的错误。所以,我已经将本机和绑定转换为AMD模块,但仍然存在问题。我是新手,也不知道这是否有道理。它们应该是模块吗?或者,我应该在某个地方将此代码添加到viewmodel中吗?无论如何,我已经检查了最新的代码以供参考。运行情况有所好转,但ENTER键绑定处理程序仍然没有启动。请发送一个包含一些修改的请求。
<header id="header">
    <h1>todos</h1>
    <input id="new-todo" type="text" data-bind="value: current, valueUpdate: 'afterkeydown', enterKey: add" placeholder="What needs to be done?" autofocus>
</header>
define(
    [
    'knockout',
    'jquery',
    'durandal/app', 
    'durandal/system', 
    'scripts/dataservice', 
    'scripts/model',
    'scripts/config',
    'scripts/bindings',
    'scripts/native'
    ], 
    function(ko, $, app, system, dataservice, model, config) {
    'use strict';

    var self = this;

    var todos = ko.observableArray([]),
        current = ko.observable(), // store the new todo value being entered
        showMode = ko.observable('all');

    // add a new todo, when enter key is pressed
    var add = function() {
        var current = current().trim();
        if (current) {
            todos.push(new model.Todo(current));
            current('');
        }
    };
    ...
define(
    [
    //'knockout', // Durandal expects knockout and $ loaded via script tag,
    //'jquery',   // no need to define them as deps as well
    'durandal/app', 
    'durandal/system', 
    'scripts/dataservice', 
    'scripts/model',
    'scripts/config',
     //'scripts/bindings',
    'scripts/native' // remove if not in AMD format
    ], 
    function(app, system, dataservice, model, config) {
    'use strict';