gpt4 book ai didi

javascript - Ember js 将 id 传递给绑定(bind)属性

转载 作者:行者123 更新时间:2023-11-28 01:11:12 25 4
gpt4 key购买 nike

是否可以将动态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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com