是否可以将动态ID传递给bind-attr
我有以下模板 -
{{#each attachments}}
<a {{bind-attr href = attachmentDownloadUrl }} download title='download attachment'>
<span class='glyphicon glyphicon-floppy-save'> </span>
</a>
{{/each}}
并且在特定控制器中想要获取当前附件ID -
attachmentDownloadUrl: function(id){
console.log(id);
return "xxx"+id;
}.property('id'),
如何传递ID?谢谢
答案 0 :(得分:1)
您不会将参数传递给计算属性,但您可以创建一个itemController
,它可以使计算属性特定于每个项目,而不是集合。
{{#each item in attachments itemController='foo'}}
<a {{bind-attr href=item.attachmentDownloadUrl }} download title='download attachment'>
<span class='glyphicon glyphicon-floppy-save'> </span>
</a>
{{/each}}
App.FooController = Em.ObjectController.extend({
attachmentDownloadUrl: function(){
return "xxx"+this.get('id');
}.property('id')
});