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