Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 如何创建html属性';s值取决于Ember.js视图呈现的项目?_Templates_Attributes_Ember.js_Attr - Fatal编程技术网

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"})
     ]});