//HTML template
requirejs([
'handlebars',
'htmlTemplates/mydiv',
'text!htmlTemplates/mydiv.html'
],
function (notUsed0, mydivData, mydivTemplate)
{
console.log(mydivData);
var theTemplate = Handlebars.compile (mydivTemplate);
$(".mydiv").append(theTemplate(mydivData));
//error Uncaught TypeError: Cannot read property 'customerName' of undefined
}
);
数据 - mydiv.js
{
customerName: "peter"
}
模板 - mydiv.html
<div> Name: {{ customerName }} </div>
mydiv 是我的 index.html 的 body 标记中的一个 DIV 元素
------edit----- 我也尝试在函数内部定义一个变量
var theData = {customerName:"Shop Page"};
现在一切正常,没有错误,但 html 仍然没有附加到我的 index.html 中带有 mydiv id 的 DIV。为什么?