私は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);
私ができるフィックスイット以下のコードを持つ:
ko.applyBindingsToNode(element, null, app.viewModel);
しかし、今、私はこのエラーを取得しています:
invalid 'in' operand jQuery.template
if (templateId in jQuery['template'])
oops。少なくともあなたはそれを認めてくれるほど大きかった、公正なプレー。 – dove
と同じようにしていない嘘つきを私に見せてください – dove
うわー...まったく同じエラーがありました。まったく同じ理由で。さて、これは私にとって役に立つ答えと疑問でした:) –