質問

ajaxの呼び出しの後にnockout.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);

しかし今、私はこのエラーを取得しています:

'in' in 'operand jquery.template

if (templateId in jQuery['template']) 
役に立ちましたか?

解決

私は馬鹿のように感じます。 jQueryテンプレートスクリプトを参照しませんでした。

他のヒント

少し混乱しているように見えます。あなたが持っている app.viewmodel.interactive その後 App.Itteractive. 。私は何かを見逃しているかもしれませんが、あなたはより簡単に名前のあるViewModelに適用して、そこから作業しようとしますか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top