Ember 无法将参数传递到操作中

Ember cannot pass parameter into action

无论我输入什么值或将其更改为 onclick="{{action ...}}",它都会不断给我未定义的值。我真的尝试了我能想到的每一种组合。我什至使用 a 标签来查看是否会保存该值。我完全不确定我应该如何获得这张图片 url。

这在 ember 中,我在代码的其他部分使用了 {{action "function name"}} 组合,但这是唯一不起作用的部分。

模板文件

<div class="gif-display">
              {{#each giffy as |gif index|}}
                  <img width="150px" {{action "selectGIF" value=gif}} src={{gif.images.original.url}}>
              {{/each}}
</div>

控制器class

selectGIF: function (num) {
  console.log("num", num)
  let newPost = this.store.createRecord('post', {
    email: this.get("session.currentUser.email"),
    body: `${gifs[num].images.original.url}`,
    timestamp: new Date().getTime(),
    image: true
  });
  gifs = ''
  newPost.save()
}

是的,我已经测试过它是否运行该功能,它确实运行了,而且图像确实显示了,所以这也不是问题。

我的问题是,是否可以将参数传递给此函数。如果没有,是否有解决方法?我应该使用辅助函数吗?

谢谢!

函数参数列表是索引列表,而不是键值集合。因此,将参数作为键值对传递是错误的。相反,应该在操作名称之后直接向助手提供参数,作为引用或文字值的 space 分隔列表:

<img {{action "selectGIF" gif}} />

来源:https://guides.emberjs.com/v3.0.0/templates/actions/#toc_action-parameters


此页面还显示可以将键值对提供给操作助手,但是这些是助手执行的参数,而不是实际操作的执行。