4

我正在使用 hottowell 模板来创建 spa 应用程序,并且我从 jquery 中得到了一个很好的错误。基本上我的问题现在开始尝试从 viewModelBinder.js (来自 durandal 库)绑定我的视图。

viewModelBinder.beforeBind(obj, view);
action();
viewModelBinder.afterBind(obj, view);

目前调用beforeBind这个代码被执行(我自己的应用程序的main.js)

kendo.ns = "kendo-";
viewModelBinder.beforeBind = function (obj, view) {
    kendo.bind(view, obj.viewModel || obj);
};

其中 kendo.bind 类似于(来自 kendo ui 库的 kendo.web.js):

function bind(dom, object) {
    var idx, length, roles = kendo.rolesFromNamespaces([].slice.call(arguments, 2));
    object = kendo.observable(object);
    dom = $(dom);
    for (idx = 0, length = dom.length; idx < length; idx++) {
        bindElement(dom[idx], object, roles);
    }
}

当我运行这条线时,从这里开始

        object = kendo.observable(object); // where object it's my viewmodel as far i see in the debuger.

我从文件 jquery-1.9.1.js 的第 4224 行得到了很多异常

div.querySelectorAll("*,:x");

和文件 jquery-1.9.1.js 的第 4242 行

matches.call( div, "[s!='']:x" );

这些异常导致控制台中的错误:“Maximum Call Stack Size Exceeded”

我怀疑是我的 html 视图,可能是某些 html 元素触发了这个问题。其他有趣的评论是,当 html 视图中的元素从可见 :false 变为可见:true 时,问题就出现了(我的视图是一个 html 表,能够显示或隐藏所选行的详细信息)

4

1 回答 1

5

What data object are you trying to bind? The "call stack exceeded" error often occurs when binding a Kendo UI component to a data object that has circular references (e.g., customer -> orders[0] -> customer). All breeze entities have circular references (e.g., customer.entityAspect.entity which points back to customer).

Therefore, you need to either train the component to ignore certain paths or insert an intermediary object that clips those paths. If you're just presenting (not updating) the object, you can make a safe copy with JSON.stringify, passing in a replacer function to exclude the circular paths.

This is a bigger topic than I have time for in this answer. Kendo UI is not the only one with this problem, I hasten to add.

于 2013-07-31T16:24:21.570 回答