【发布时间】:2014-05-22 05:46:07
【问题描述】:
我正在尝试实现 Spine.js 文档中给出的 Todo 示例,此处给出:http://spinejs.com/docs/example_tasks
只有我想使用 Handlebars 而不是 jQuery.tmpl。我正在使用 Handlebars 1.0.rc.1
但是,当我尝试调用时:
template: Handlebars.compile($('#history-template').html()),
render: function(){
var t = this.template(this.item);
this.replace(t);
return this;
}
Handlebars 在this.template(this.item) 处抛出异常:
Uncaught TypeError: Cannot call method 'match' of undefined
在 Handlebars 词法分析器中,this._input 以未定义的形式返回。
我的模板如下:
<script id='history-template' type='text/x-handlebars-template'>
<div class="content-inner {{#if viewed}}msg_unseen{{/if}}">
<div>{{data}}</div>
</div>
</script>
数据:
"[{"data":"hello","id":"c-0"}]"
有什么想法吗?
【问题讨论】:
-
以上描述中的错别字,应通过#history-template选择。但不幸的是,仍然无法使用给定的数据模型,这就是 Spine 处理其 JSON 的方式。
标签: javascript handlebars.js spine.js