我正在测试Ember.js的主要特性。根据提供的指南,以下代码使用简单的绑定和自动更新模板应该输出Hey there! This is My Ember.js Test Application!,但它输出的是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();哈佛商学院:
<script type="text/x-handlebars" data-template-name="application">
<h1>Hey there! This is <b>{{name}}</b>!</h1>
</script>我是不是做错了什么?
发布于 2012-12-28 02:11:42
当您从模板中引用视图的属性时,必须在其前面加上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'
});https://stackoverflow.com/questions/14059009
复制相似问题