Templates 如何创建html属性';s值取决于Ember.js视图呈现的项目?
假设我有这样的观点:Templates 如何创建html属性';s值取决于Ember.js视图呈现的项目?,templates,attributes,ember.js,attr,Templates,Attributes,Ember.js,Attr,假设我有这样的观点: App.AnchorView = Ember.View.extend({ tagName: 'a', attributeBindings: ['href'] }); 和类定义: App.Item = Ember.Object.extend({ name: "Unknown Entry", location: "" }); 以及该类的一个实例: App.Item.create({ name: "Google", location: "http:
App.AnchorView = Ember.View.extend({
tagName: 'a',
attributeBindings: ['href']
});
和类定义:
App.Item = Ember.Object.extend({
name: "Unknown Entry",
location: ""
});
以及该类的一个实例:
App.Item.create({
name: "Google",
location: "http://www.google.com"
});
我的模板是:
{{#view App.AnchorView}}{{name}}{{/view}}
我希望它呈现为:
<a href="http://www.google.com">Google</a>
如何做到这一点?这里有一个使用bindAttr href和ItemsController的超级快速方法:有关更详细的文档,请查看
{{{#每个App.ItemsController}
{{/每个}}
App.ItemsController=Ember.ArrayController.create({
内容:[
App.Item.create({名称:“谷歌”,位置:“http://www.google.com"})
]});
谢谢,但我特别想知道是否可以在视图本身生成的元素上更改它
{{#each App.ItemsController}}
<a {{bindAttr href="location"}}>{{name}}</a>
{{/each}}
App.ItemsController = Ember.ArrayController.create({
content: [
App.Item.create({ name: "Google", location: "http://www.google.com"})
]});