我试图让Quintout.js在打电话后更新我的视图,但没有运气。我一直在下面遇到错误。它出错了 app.interactive.updateBindings. 。 parsebindingAttribute ViewModel参数不确定。

错误:

无法解析绑定属性。信息:
参考: interactive 没有定义;
属性值: template: { name: 'answerTmpl', foreach: interactive.answers }

动态HTML:

<div id="questions">
    <div id="answers" data-bind="template: { name: 'answerTmpl', foreach: interactive.answers }">
    </div>
</div>

<script type="text/javascript">

    app.viewModel.interactive.answers(@Html.Raw(@Model.Answers.ToJson()));
    app.interactive.updateBindings(document.getElementById('answers'));

</script>
<script id="answerTmpl" type="text/html">
<div>
  <span></span>  <input type="checkbox" name="Answer" />
</div>
</script>

我的.js文件:

(function (app, $, undefined) {

    app.viewModel = {};
    app.interactive = {};
    app.interactive.callback = function () { };

 app.viewModel.interactive = {
        content: ko.observable('test'),
        answers: ko.observableArray()
    };

        app.interactive.init = function () {

        ko.applyBindings(app.viewModel);
    };

    app.interactive.updateBindings = function (element) {
        ko.applyBindingsToNode(element);
    };

    app.interactive.init();

})(window.app = window.app || {}, jQuery);

我可以使用以下代码进行修复:

ko.applyBindingsToNode(element, null, app.viewModel);

但是现在我遇到了这个错误:

无效的“在”操作数jquery.template

if (templateId in jQuery['template']) 
有帮助吗?

解决方案

我感觉像个白痴。我什至没有引用jQuery模板脚本。

其他提示

看起来有些混乱。你有 app.viewmodel.interactive 接着 app. Interactive. 。我很可能会丢失一些东西,但是您会尝试将框架应用于更简单的名称viewmodel并从那里工作吗?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top