本文介绍了把手把字符串或把手AST传递给把手编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道它被问了很多次,我已经看了答案,并且不确定我出错的地方。
我查看了Handlebarsjs上的文档,并遵循了一个教程,并且两次都得到相同的错误。
<!DOCTYPE html>
< html>
< head>
< script src =handlebars-v1.3.0.js>< / script>
< script src =jquery.min.js>< / script>
< script src =test.js>< / script>
< / head>
< body>
< script id =headertype =text / x-handlebars-template>
div {{headerTitle}} div
今天是{{weekDay}}
< / script>
< / body>
< / html>
这是我的Javascript
<$ p $
var theData = {headerTitle:name,weekDay:monday}
var theTemplateScript = $(#header)。html();
var theTemplate = Handlebars.compile(theTemplateScript);
$(document.body).append(theTemplate(theData));
我继续收到以下错误,但我不确定为什么
未捕获错误:您必须将字符串或Handlebars AST传递给Handlebars.compile。
您传递了undefined
解决方案
.TemplateScript加载到DOM之前的.compile()。将您的test.js移动到模板脚本的下方,您应该顺其自然。
I know its been asked many times, I have looked at the answers and not sure where I am going wrong.
I have looked at the docs on Handlebarsjs and followed a tutorial and both times I am getting the same error.
<!DOCTYPE html>
<html>
<head>
<script src="handlebars-v1.3.0.js"></script>
<script src="jquery.min.js"></script>
<script src="test.js"></script>
</head>
<body>
<script id="header" type="text/x-handlebars-template">
div {{ headerTitle }} div
Today is {{weekDay}}
</script>
</body>
</html>
And this is my Javascript
var theData = {headerTitle:"name", weekDay:"monday"}
var theTemplateScript = $("#header").html();
var theTemplate = Handlebars.compile(theTemplateScript);
$(document.body).append(theTemplate(theData));
I keep on getting the following error and i am unsure why
Uncaught Error: You must pass a string or Handlebars AST to Handlebars.compile.
You passed undefined
解决方案
You are running Handlebars.compile() before theTemplateScript is loaded into the DOM. Move your test.js down below the template script and you should be good to go.
这篇关于把手把字符串或把手AST传递给把手编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!