使用FineUploader在onSubmitted中未定义getItemByFileId [英] getItemByFileId undefined in onSubmitted with FineUploader
问题描述
我正在研究 AngularJS示例
这时,上传正常(到s3),但是我的onSubmit回调爆炸: [Fine Uploader 5.0。 2]'onSubmitted'回调中捕获了异常-未定义不是函数
At this point, uploads are working (to s3), but my onSubmit callback exploding: [Fine Uploader 5.0.2] Caught exception in 'onSubmitted' callback - undefined is not a function
这可能是一个fefeescript粗箭头问题,因为我将我的构建环境(以及我对coffeescript的偏好)的例子,但是无论如何我还是很困惑。
This may be a cofeescript fat arrow problem, since I transpiled the example to coffeescript for my build environment (and my preference for coffeescript), but I'm stumped anyhow.
以下是选项的相关用法。
Here's the relevant dict for the options.
callbacks: {
onSubmitted: (id, name) =>
console.log "calling onSubmitted(#{id}, #{name})"
console.log "This shouldn't be undefined: #{@getItemByFileId}"
# but it _is_ undefined
$file = $(@getItemByFileId(id))
console.log $file
$thumbnail = $file.find(".qq-thumbnail-selector")
$thumbnail.click ->
openLargerPreview(
$scope,
$(element),
largePreviewSize,
id,
name
)
return
return
}
以下是呈现的瘦箭头版本(请参见下面的评论)进入JS:
Here's the skinny arrow version (see comments below) as rendered into JS:
callbacks: {
onSubmitted: function(id, name) {
var $file, $thumbnail;
console.log("calling onSubmitted(" + id + ", " + name + ")");
$file = $(getItemByFileId(id));
console.log($file);
$thumbnail = $file.find(".qq-thumbnail-selector");
$thumbnail.click(function() {
openLargerPreview($scope, $(element), largePreviewSize, id, name);
});
}
}
结果(当我上传内容时)为
the result (when I upload something) is
[Fine Uploader 5.0.2] Received 1 files or inputs.
[Fine Uploader 5.0.2] Attempting to validate image.
calling onSubmitted(0, IMAG0161.jpg)
This shouldn't be undefined: undefined
[Fine Uploader 5.0.2] Caught exception in 'onSubmitted' callback - undefined is not a function
如代码中所示,问题(据我了解)是 @getItemByFileId
没有在 this
上正确定义,而(据我所知) this
应该是fineuploaderS3对象。
as indicated in the code, the problem (as I understand it) is that @getItemByFileId
is not defined on this
properly, where (again, as I understand it) this
should be the fineuploaderS3 object.
推荐答案
在Fine Uploader事件处理程序中无需使用粗箭头。事件处理程序的上下文将为您设置(通过Fine Uploader)为Fine Uploader实例。只需使用细箭头即可。
There's no need to use a fat arrow in the Fine Uploader event handlers. The context of the event handler will be set to the Fine Uploader instance for you (by Fine Uploader). Just use a "skinny arrow".
这篇关于使用FineUploader在onSubmitted中未定义getItemByFileId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!