Warm tip: This article is reproduced from serverfault.com, please click

其他-带有递归调用的 FilePond 选项

(其他 - FilePond Options with recursive call of fetch)

发布于 2021-01-13 21:27:54
FilePond.setOptions({        
    server: {            
        fetch: (url, load, error, progress, abort, headers) => {            
            fetch(url)
                .then(res => res.blob())
                .then(load);
        }

我在网上找到了这个配置。我不明白为什么会这样。这不应该导致堆栈溢出吗?

IMO 函数正在递归调用自己还是我有什么问题?

Questioner
Felix D.
Viewed
0
Rik 2021-01-18 16:30:02

在这个例子中,第一个fetch是 的属性server,第二个fetch是 JavaScript 本机 fetch 函数。

你也可以这样写,这样可能会更清楚一些?

function getData(url, load) {
  return fetch(url)
    .then(res => res.blob())
    .then(load)
}

const options = {
  server: {
    fetch: getData
  }
}

FilePond.setOptions(options);