删除地图功能

时间:2016-12-19 10:56:20

标签: javascript promise

我有以下javascript承诺,我循环浏览文档列表,逐个上传到Dropbox(API调用),获取每个文档的共享链接,将它们保存在数组,然后生成一个包含这些链接的电子邮件。

docs = self.checkedDocs();
body = "Please click on the link(s) below to view your document(s): ";
$.when.apply($, docs.map(function (doc) {
    return self.service.getDropboxLink(doc).then(function (dropboxLink) {
         return lineBreak + doc.documentDescription() + ": " + dropboxLink;
    });
})).done(function () {
    var attachment = [].join.call(arguments, '');
    formatEmail(attachment, body);
});

我尝试做的事情完全相同,但只有一个文件,我明白我不再需要map但是我&# 39;我不知道该怎么做。

你可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

正好使用$.when构造,因为您想要等待多个承诺。只有一个文档,大部分复杂性都消失了:

self.service.getDropboxLink(doc).then(function(dropboxLink) {
     var attachment = doc.documentDescription() + ": " + dropboxLink;
     openEmail("Please click on the link below to view your document: ", attachment);        
});