Mik*_*ynn 2 ajax asp.net-mvc-3 knockout.js
我试图让knockout.js在ajax调用后更新我的视图,但没有运气.我一直收到下面的错误.它出错了app.interactive.updateBindings.parseBindingAttribute viewModel参数未定义.
错误:
无法解析绑定属性.消息:
ReferenceError: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>
Run Code Online (Sandbox Code Playgroud)
我的.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);
Run Code Online (Sandbox Code Playgroud)
我可以使用以下代码修复:
ko.applyBindingsToNode(element, null, app.viewModel);
Run Code Online (Sandbox Code Playgroud)
但是现在我收到了这个错误:
'in'operand jQuery.template无效
if (templateId in jQuery['template'])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1597 次 |
| 最近记录: |