gpt4 book ai didi

javascript - 如何在 ember-file-upload 中执行组件操作而不是路由操作

转载 作者:行者123 更新时间:2023-11-30 21:00:47 26 4
gpt4 key购买 nike

我正在使用这个包 https://github.com/tim-evans/ember-file-upload

在他们的示例中,他们调用路由操作来上传图片

             onfileadd=(route-action "uploadImage")}}

但是我想改为调用组件操作

我试过

                 onfileadd="uploadImage"}}

并在组件中添加了 Action :

uploadImage: function (file) {
console.log(file);
let self = this;
RSVP.cast(Ember.$.get(ENV.APP.API_HOST + "/v1/teams/signed_url/")).then(function (response) {
return file.upload(response.url, {
data: response.credentials
});
}).then(function (response) {
self.set('url', response.headers.Location);
});
},

但是我得到了错误:

Uncaught TypeError: Cannot read property 'uploadImage' of undefined

如果我将它移动到路由,操作将按预期工作,但我需要更新组件中的正确属性(路由中不存在的属性)

知道我可以做些什么来将其更改为组件功能吗?

最佳答案

你应该使用 action助手:

onfileadd=(action "uploadImage")}}

还要确保 uploadImage 在组件的 actions 散列中:

export default Ember.Component.extend({
// ...
actions: {
uploadImage() { // <-- make sure this is inside the actions hash
// ...
}
}
})

关于javascript - 如何在 ember-file-upload 中执行组件操作而不是路由操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47149841/

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