1

I'm testing the main features of Ember.js. According to the provided Guide, the following code, using simply Bindings and Auto-Updating templates should output Hey there! This is My Ember.js Test Application! but instead it outputs Hey there! This is !.

JS:

// Create the application.
var Application = Ember.Application.create();

// Define the application constants.
Application.Constants = Ember.Object.extend({
    name: 'My Ember.js Test Application'
});

// Create the application controller.
Application.ApplicationController = Ember.Controller.extend();

// Create the application view.
Application.ApplicationView = Ember.View.extend({
    templateName: 'application',
    nameBinding: 'Application.Constants.name'
});

// Create the router.
Application.Router = Ember.Router.extend({
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            route: '/'
        })
    })
})

// Initialize the application.
Application.initialize();

HBS:

<script type="text/x-handlebars" data-template-name="application">
    <h1>Hey there! This is <b>{{name}}</b>!</h1>
</script>

Is there something I am doing wrong?

4

1 回答 1

2

当您从模板中引用视图的属性时,您必须在其前面加上view关键字。

所以试试

<script type="text/x-handlebars" data-template-name="application">
  <h1>Hey there! This is <b>{{view.name}}</b>!</h1>
</script>

它应该工作。

哦,我忘记了,绑定错误,你必须引用一个对象而不是一个类。尝试

Application.constants = Ember.Object.create({
  name: 'My Ember.js Test Application'
});

Application.ApplicationView = Ember.View.extend({
  templateName: 'application',
  nameBinding: 'Application.constants.name'
});
于 2012-12-27T18:11:42.490 回答