5

我没有找到任何开始使用 Ember.js 的好文档。请帮助我,这是我从http://emberjs.com/documentation/尝试的一个简单示例,但屏幕上没有显示任何内容。

Error:  MyApp is not defined  

Javascript:app.js

    MyApp.president = Ember.Object.create({
  firstName: "Barack",
  lastName: "Obama",
  fullName: function() {
    return this.get('firstName') + ' ' + this.get('lastName');
  // Tell Ember that this computed property depends on firstName
  // and lastName
  }.property('firstName', 'lastName')
});

HTML

<p>
<script type="text/x-handlebars">
  The President of the United States is {{MyApp.president.fullName}}.
</script>
</p>

我包含了入门工具包中的所有 JS 文件。

4

2 回答 2

6

你忘了定义 MyApp,它必须是 Ember.Application 的一个实例:

var MyApp = Ember.Application.create({});

这是我几周前发现的一个非常全面的教程,也许它对您的学习目的有用:http: //www.appliness.com/flame-on-a-beginners-guide-to-ember-js/

于 2012-12-29T14:47:45.443 回答
4

你必须定义MyApp

我在这里创建了一个工作示例。单击运行按钮以查看结果。

HTML

<p>
<script type="text/x-handlebars">
  The President of the United States is {{MyApp.president.fullName}}.
</script>
</p>​

代码

window.MyApp = Ember.Application.create();

MyApp.president = Ember.Object.create({
  firstName: "Barack",
  lastName: "Obama",
  fullName: function() {
    return this.get('firstName') + ' ' + this.get('lastName');
  }.property('firstName', 'lastName')
});
​
于 2012-12-29T14:41:15.010 回答