【问题标题】:Ember - Missing helper action for HBS filesEmber - 缺少 HBS 文件的辅助操作
【发布时间】:2015-05-08 09:16:58
【问题描述】:

我写了一个带有 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:

<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>

【问题讨论】:

标签: ember.js handlebars.js


【解决方案1】:

您的演示中的代码和有问题的代码不同。 Here is a fixed demo based on the code in ur question.

修复您提供的演示可能需要您包含原版车把库,因为 ember 现在使用的是构建在车把之上的 HTMLBars,但有点不同。

Em.Handlebars.compile 现在实际上是使用 HTMLBars 编译方法。 You can see here.

您可能需要使用 https://github.com/rwjblue/broccoli-ember-inline-template-compiler 之类的东西

【讨论】:

  • 我需要的是一个 HBS 文件列表,每个文件都包含其模板的操作。我想使用 ember 将这些模板包含在 HTML 中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 1970-01-01
  • 2013-02-09
  • 2018-11-16
  • 1970-01-01
  • 2016-06-11
相关资源
最近更新 更多