首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ember.js绑定和模板

Ember.js绑定和模板
EN

Stack Overflow用户
提问于 2012-12-28 01:56:27
回答 1查看 1.1K关注 0票数 1

我正在测试Ember.js的主要特性。根据提供的指南,以下代码使用简单的绑定和自动更新模板应该输出Hey there! This is My Ember.js Test Application!,但它输出的是Hey there! This is !

JS:

代码语言:javascript
复制
// 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();

哈佛商学院:

代码语言:javascript
复制
<script type="text/x-handlebars" data-template-name="application">
    <h1>Hey there! This is <b>{{name}}</b>!</h1>
</script>

我是不是做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-28 02:11:42

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

所以试一试

代码语言:javascript
复制
<script type="text/x-handlebars" data-template-name="application">
  <h1>Hey there! This is <b>{{view.name}}</b>!</h1>
</script>

应该能行得通。

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

代码语言:javascript
复制
Application.constants = Ember.Object.create({
  name: 'My Ember.js Test Application'
});

代码语言:javascript
复制
Application.ApplicationView = Ember.View.extend({
  templateName: 'application',
  nameBinding: 'Application.constants.name'
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14059009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档