【问题标题】:Hello World in EmberJs ErrorEmberJs 错误中的 Hello World
【发布时间】:2016-12-03 19:59:12
【问题描述】:

我正在 EmberJs 中编写第一个程序为 "Hello World" 打印,但出现错误。有人可以帮我吗?

HTML

<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.7.0/ember.min.js"></script>
    <script>
      App = Ember.Application.create();
      App.Router.map(function() {
        this.resource('index', { path: '/' }, function() {});
        this.resource('hi', { path: '/hi' }, function() {});
      });
    </script>
    <script type="text/x-handlebars" data-template-name='index'>
      <p>index!</p>
      <p>{{#linkTo hi}}hi{{/linkTo}}</p>
    </script>
    <script type="text/x-handlebars" data-template-name='hi'>
      hello world!
    </script>
</head>
<body>
</body>
</html> 

错误

【问题讨论】:

  • 从 Ember 2 开始,开发 Ember 应用程序的首选方法是使用 ember-cli 工作流,它通过包含构建项目所需的所有内容来防止此类错误。 Tom DaleThe Road to Ember 2.0 RFC 中提到了这一点。我认为您应该查看 Ember quick start 以了解您在 Ember 环境中的第一步,它涵盖了 Hello world 应用程序的所有内容。

标签: javascript model-view-controller ember.js


【解决方案1】:

您需要包含 ember-template-compiler 而不是把手:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.7.0/ember.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.7.0/ember-template-compiler.js"></script>

您也不能使用 linkTo 助手,因为它已被弃用,这就是您收到另一个错误的原因。这里是working fiddle.

【讨论】:

  • 仍然出现错误:“ember.min.js:5 Uncaught TypeError: Cannot read property 'isHelperInstance' of undefined”。你能分享一下工作小提琴吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 1970-01-01
  • 1970-01-01
  • 2017-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多