是否可以将动态ID传递给bind-attr
我有以下模板 -
{{#each attachments}}
<a {{bind-attr href = attachmentDownloadUrl }} download title='download attachment'>
<span class='glyphicon glyphicon-floppy-save'> </span>
</a>
{{/each}}
并且在特定 Controller 中想要获取当前附件ID -
attachmentDownloadUrl: function(id){
console.log(id);
return "xxx"+id;
}.property('id'),
如何传递 id ?谢谢
最佳答案
您不会将参数传递给计算属性,但您可以创建一个 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}}
项目 Controller
App.FooController = Em.ObjectController.extend({
attachmentDownloadUrl: function(){
return "xxx"+this.get('id');
}.property('id')
});
关于javascript - Ember js 将 id 传递给绑定(bind)属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24407707/