3

我正在使用来自 Emebr JS 的入门工具包,并在应用程序模板中添加了一个带有 {{action hello}} 的简单锚标记。

我正在使用把手预编译器预编译模板。当我尝试运行它时,它会引发错误。

未捕获的错误:找不到属性“操作”

以前我用ember-1.0.pre.js做同样的事情,效果很好。但是当我包含新的 ember 库(ember-1.0.0-pre.2.js)时,它会抛出这个错误。

在这两种情况下,我都使用handlebars-1.0.rc.1.min.js

谁能帮我解决这个问题。下面列出了我正在使用的车把和库的详细信息。

使用车把预编译器编译的模板。应用程序.handlebars

<h1>Hello from Ember.js</h1> 
<a {{action hello}}>Say Hello!</a>

我的 HTML 页面:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>
  <script src="js/libs/handlebars-1.0.0.beta.6.js"></script>
  <script src="js/libs/ember-1.0.0-pre.2.min.js"></script>

  <script src="handlebars/compiled/views.handlebars.js"></script>

  <script src="js/app.js"></script>

views.handlebars.js 包含已编译的车把。

应用程序.js:

var App = Ember.Application.create();

App.ApplicationController = Ember.Controller.extend();
App.ApplicationView = Ember.View.extend({
  templateName: 'application'
});

App.Router = Ember.Router.extend({
  root: Ember.Route.extend({
    index: Ember.Route.extend({
      route: '/'
    }),
    hello: function() {
        console.log("Hello and Welcome");
    }
  })
})

App.initialize();
4

2 回答 2

5

在为 ember 预编译把手视图时,您需要使用 Ember.Handlebars,而不是 Handlebars。我怀疑这可能是问题所在。

更多讨论:Emberjs Handlebars 预编译

于 2012-11-12T17:25:20.497 回答
1

感谢您的链接,但我开始使用 ember-precompile 而不是车把预编译。您可以在https://github.com/gabrielgrant/node-ember-precompile找到 ember-precompile

该模块使用较旧的车把和 ember 库,在运行此模块之前必须将库升级到最新版本,然后运行它。可以在“index.js”中修改库的路径。添加最新的库和修改“index.js”对我有用。

于 2012-11-13T13:02:41.203 回答