0

次のスクリプト テンプレートがあります。

<script id="template" type="text/x-jsrender">
    <div>
        <label>Name</label>
        <input data-link="FirstName" type="text" />
    </div>


    <button>Search</button>
</script>

次のコマンドで jsView を起動します。

$.templates("#template").link("#result", model);

モデルはjsオブジェクトです

function myModel() {
    this.FirstName = "";
}

残念ながら、linkコマンドはエラーを引き起こします:

TypeError: elem.dispatchEvent is not a function

何が間違っている可能性がありますか?

4

1 に答える 1

0

モデルを構築している方法でしょうか?

たとえば、これは機能しません ( fiddle ):

function myModel() {
    this.FirstName = "",
}
var model = myModel();
$.templates("#template").link("#result", model);

しかし、これは機能します(フィドル):

var model= {
    FirstName : "",
}

$.templates("#template").link("#result", model);

これもそうです(fiddle):

function myModel() {
    this.FirstName = "",
}
var model = new myModel(); //<---the new keyword makes the difference
$.templates("#template").link("#result", model);
于 2014-05-12T14:58:49.867 に答える