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

这可能是您构建模型的方式吗?

例如,这不起作用(小提琴):

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

但这有效(小提琴):

var model= {
    FirstName : "",
}

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

就像这个(小提琴)一样:

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 回答