Ember.js绑定和模板
Ember.js Bindings and Templates
我正在测试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();
HBS:
<script type="text/x-handlebars" data-template-name="application">
<h1>Hey there! This is <b>{{name}}</b>!</h1>
</script>
我做错了什么吗?
当你从模板中引用视图的属性时,你必须在它前面加上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'
});
相关文章:
- react.js中的密钥绑定
- 如何销毁/删除/取消绑定SnapSVG.js
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- 淘汰赛.JS'启用'长度绑定条件不起作用
- Backbone.js将模型绑定到视图时出错
- 使用knockout.js将数组绑定到视图模型
- 如何使用Jasmine测试Knockout.js点击绑定
- 在offline.js中绑定事件
- Ember.js:将Em.$.getJSON转换为promise并将响应绑定到控制器上下文的正确方法
- 基本D3.js:如何将具有其他属性的数据绑定到元素
- 是否可以为React'打开React.js自动绑定;s类模型
- 是否可以使用Sinon.JS检查函数参数绑定是否正确
- knockout.js中的绑定多下拉列表
- 一种将Apache Thrift JS绑定与Backbone.JS一起使用的方法
- 为SEO的数据绑定JS预加载数据
- C3 中的双向数据绑定.js AngularJS 中的双向数据绑定
- 用于绑定 JS 对象以进行回调的解决方案
- 如何解绑定JS bundle文件
- 根据鼠标位置绑定js事件:性能杀手与否