车把编译错误
handlebar compilation errors
嗨,我一直在尝试使用 backbonejs 和车把模板,但似乎我的 jSON 是错误的,或者数据没有正确解析。获得
Uncaught Error: You must pass a string to Handlebars.compile. You passed undefined
代码可以在以下位置找到
斯菲德尔
任何建议将不胜感激
你的小提琴以各种方式被打破,但很有可能你正在这样做:
template: Handlebars.compile($('#tpl-page-list-item').html()),
在有可用的#tpl-page-list-item
之前。如果您的页面如下所示,则会发生这种情况:
<script src="your_backbone_javascript.js"></script>
<script id="tpl-page-list-item" ...></script>
因为您的主干视图将在<script id="tpl-page-list-item">
添加到 DOM 之前被解析。您可以将 Backbone 视图包装在文档就绪处理程序中(使用适当的命名空间来考虑函数包装器):
$(function() {
window.PageListItemView = Backbone.View.extend({
template: Handlebars.compile($('#tpl-page-list-item').html()),
//...
});
});
或者在实例化视图时编译模板:
initialize: function() {
// Or check if it is in the prototype and put the compiled template
// in the prototype if you're using the view multiple times...
this.template = Handlebars.compile($('#tpl-page-list-item').html());
//...
}
相关文章:
- Mocha react本地路由器编译错误
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- 使用SeleniumWebdriver将文本复制到文件时出现编译错误的解决方案
- 无法读取属性'编译'的未定义.可以'我似乎没有发现错误
- 获取模板是用我的Node.JS应用程序的新版本Handlebars错误预编译的
- Gulp 4 TypeScript编译错误
- Gulp.js 在 LESS 文件中出现错误后,在观看时停止编译 LESS
- 如何在 Node.js 应用程序中编译或检查语法错误
- 车把编译错误
- 编译 TypeScript 时出现 Ionic 2 语法错误
- 在javascript中使用剃刀语法时出现条件编译错误/警告(在此上下文中不存在cc_on)
- 谷歌浏览器中的韦伯尔着色器编译错误
- 主干.js - n捕获异常:语法错误:函数构造函数:无法编译函数
- 在 yeoman 中使用动画模块编译 AngularJS 应用程序会给出未知的提供程序错误
- 咖啡脚本错误编译
- Bootstrap 不会编译 css 语法错误:无法读取属性 'toCSS'
- 当我编译 NodeJS 时,我收到一个编译错误
- Gulp 不通知 JS 错误,也不在运行 gulp 时编译 scss 文件
- 如何在节点sass编译sass代码时抛出自定义错误
- Babel / Rollup错误编译和捆绑ES2017