0
我努力学习JavaScript模板,即dustjs的特性“SUBSTR”,但我遇到的问题,我认为这是如此基本的甚至是Google不能回答吧:)遗漏的类型错误:无法读取未定义Dustjs
这里是代码这是最简单的形式
<button class="getData" onClick="clicker()">Get Data</button>
<ul class="vodka">
<script id="vodka" type="text/x-template">
<li>{name}</li>
</script>
</ul>
的Javascript
window.addEventListener("load", clicker)
function clicker()
{
getData();
}
function getData()
{
var data = {name:"Vodka", degree:97}
var source = $("#vodka").html();
var template = dust.compile(source, "vodkaTemplate");
dust.loadSource(template);
dust.render("vodkaTemplate", data, function(err, res){
$(".vodka").html(res)
console.log(res)
})
}
在初始化过程中模板呈现完美,但点击按钮会导致错误
Uncaught TypeError: Cannot read property 'substr' of undefined
我在做什么错?
请在codepen,plunkr,jsbin或类似网站上提供一个运行示例。 – 2015-02-23 15:43:19
这里,但jsbin一直抛出奇怪的错误 [链接](http://jsbin.com/yukojutumo/1/edit?html,console,output) – 2015-02-23 16:03:44