我用div写了一个html。
我有两个hbs文件。我把其中一张画成了部分,另一张则和正常一样。我无法调用模板上的操作。我得到缺少助手错误。
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="holder">
</div>
<script src="js/libs/jquery-v1.11.1.js"></script>
<script src="js/libs/handlebars-v1.3.0.js"></script>
<script src="js/libs/ember-v1.6.1.js"></script>
<script src="js/libs/ember-data.js"></script>
<script src="js/app.js"></script>
</body>
</html>JS:
var data={title: "My New Post", body: "This is my first post!"};
function getTemplate(templateName,hbsPath,type){
$.ajax({
url: hbsPath, //ex. js/templates/mytemplate.handlebars
cache: true
}).done(function (src) {
if (type === "partial") {
Handlebars.registerPartial(templateName, $(src).html());
} else {
template = Handlebars.compile($(src).html());
temp=template(data);
$("#holder").append(temp);
}
});
}
getTemplate("dummy","/Test/templates/dummy.hbs","partial");
getTemplate("dummy","/Test/templates/application.hbs");
App = Ember.Application.create({});
App.Router.map(function(){
this.resource('dummy');
});
App.ApplicationController=Ember.ObjectController.extend({
needs:['dummy'],
actions:{
refresh: function(){
alert("application template refresh");
}
}
});
App.DummyController=Ember.ObjectController.extend({
actions:{
refresh: function(){
alert("dummy template refresh");
}
}
});application.hbs: HBS:
<script id="application" type="text/x-handlebars-template">
{{> dummy}}
</script>dummy.hbs:
<script type="text/x-handlebars" data-template-name='dummy'>
<div {{action 'refresh' target="controllers.dummy"}}>
Refresh
</div>
<div {{action 'refresh'}}>
Refresh
</div>
</script>发布于 2015-05-08 18:08:56
您演示中的代码和所讨论的代码是不同的。下面是一个基于您问题中的代码的固定演示。
修复演示你提供的可能需要你包括香草车把库,因为恩伯现在使用的是HTMLBars,这是建立在车把之上,但有点不同。
Em.Handlebars.compile现在实际上正在使用HTMLBars编译方法。你可以在这里看到。
您可能需要使用类似于https://github.com/rwjblue/broccoli-ember-inline-template-compiler的东西
https://stackoverflow.com/questions/30120136
复制相似问题