我想獲得knockout.js更新我的觀點後,ajax調用,但沒有運氣。我不斷收到下面的錯誤。它在app.interactive.updateBindings
錯誤。 parseBindingAttribute viewModel參數未定義。Knockout.js不更新從動態AJAX調用視圖
錯誤:
Unable to parse binding attribute. Message:
ReferenceError:interactive
is not defined;
Attribute value: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);
我可以用的fixit下面的代碼:
ko.applyBindingsToNode(element, null, app.viewModel);
但現在我得到這個錯誤:
invalid 'in' operand jQuery.template
if (templateId in jQuery['template'])
oops。至少你足夠大以承認它,公平競爭。 – dove
並告訴我誰也沒有這樣做的騙子 – dove
哇...我只是有完全相同的錯誤。完全相同的原因。那麼,這原來是一個有用的答案和問題:) –