{"id":106998,"date":"2020-05-29T05:53:52","date_gmt":"2020-05-28T21:53:52","guid":{"rendered":"http:\/\/4563.org\/?p=106998"},"modified":"2020-05-30T00:42:15","modified_gmt":"2020-05-29T16:42:15","slug":"javascript-%e4%bb%a3%e7%a0%81%e6%89%a7%e8%a1%8c%e5%85%88%e5%90%8e%e9%a1%ba%e5%ba%8f%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=106998","title":{"rendered":"Javascript \u4ee3\u7801\u6267\u884c\u5148\u540e\u987a\u5e8f\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Javascript \u4ee3\u7801\u6267\u884c\u5148\u540e\u987a\u5e8f\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sudoy <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>hello \u5927\u5bb6\u597d\uff0c<\/p>\n<p>\u6211\u4e4b\u524d\u4e00\u76f4\u7528 python \u5199\u4e00\u4e9b\u5c0f\u5de5\u5177\uff0c\u6700\u8fd1\u5f00\u59cb\u7528 JS \u5199\u4e1c\u897f\uff0c\u53d1\u73b0\u5404\u79cd\u4e0d\u9002\u5e94\uff1a\u8981\u4e48\u5fd8\u8bb0\u653e <code>;<\/code> , \u8981\u4e48\u6570\u4e0d\u6e05 <code>{<\/code> \u548c <code>}<\/code> \u662f\u5426\u6210\u5bf9\u3002 \u8fd9\u4e9b\u90fd\u8fd8\u597d\uff0c\u591a\u5199\u4e00\u5199\u4e5f\u5c31\u4e60\u60ef\u4e86\uff0c\u73b0\u5728\u78b0\u5230\u4e00\u4e2a\u4ee3\u7801\u6267\u884c\u987a\u5e8f\u7684\u903b\u8f91\u95ee\u9898\uff1a\u6211\u6709\u4e00\u4e2a\u7ec4\u8ba2\u5355\u53f7\u7801\uff0c\u6bcf\u4e2a\u8ba2\u5355\u53f7\u7801\u90fd\u8981\u62ff\u53bb\u8fdb\u884c GET \u8bf7\u6c42\uff0c\u8bf7\u6c42\u7ed3\u679c\u6709\u4e00\u4e2a\u53d8\u91cf\u8981\u4e48 <code>true<\/code> \u8981\u4e48 <code>false<\/code>\uff0c\u6211\u9700\u8981\u5c06\u6839\u636e\u8fd9\u4e2a\u53d8\u91cf\u5c06\u539f\u59cb\u7684\u8ba2\u5355\u53f7\u7801\u5206\u4e24\u7ec4\u3002<\/p>\n<p>\u5047\u8bbe\u8ba2\u5355\u53f7\u7801\u5217\u8868\u4e3a\uff1aordersID = [11, 12, 13, 21]<\/p>\n<h2>\u5982\u679c\u662f python\uff0c\u6211\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/h2>\n<pre><code>ordersID = [11, 12, 13, 21]; successful = list(); fail = list(); for x in ordersID:   if (...):     successful.append(x)   else:     fail.append(x) print(successful, fail) # [11,12, 13] [21] <\/code><\/pre>\n<p>\u4e3a\u4e86\u7cbe\u7b80\u6211\u628a\u6761\u4ef6\u90e8\u5206\u7701\u6389\u4e86<\/p>\n<h2>Javascript \u6211\u662f\u8fd9\u6837\u5199\u7684\uff1a<\/h2>\n<pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt;     &lt;meta charset=\"UTF-8\"&gt;     &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;     &lt;title&gt;Document&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt;     &lt;h1&gt;Testing!&lt;\/h1&gt;     &lt;script&gt;         var ordersID = ['11', '12', '13', '21'];         var successful = [];         var fail = [];         function makeRequest(arg) {             fetch(`https:\/\/jsonplaceholder.typicode.com\/posts\/${arg}`, {method: 'GET'})             .then(res =&gt; res.json())             .then(function (res) {                 if (res.userId == 2) {                     console.log(res);                     successful.push(arg);                     fetch('https:\/\/jsonplaceholder.typicode.com\/posts', {                         method: 'POST',                         body: JSON.stringify({                             title: 'Some title',                             body: arg,                             userId: 2                         }),                         headers: {                             'Content-type': 'application\/json; charset=UTF-8'                         }                     })                     .then(res =&gt; res.json())                     .then(console.log)                 } else {                     console.log('userId != 2');                     fail.push(arg)                 }             });         };         for (i = 0; i &lt; ordersID.length; i++) {makeRequest(ordersID[i]); console.log(successful, fail)};     &lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>\u6211\u671f\u671b\u7684\u7ed3\u679c\u662f\u8fd4\u56de\u4e00\u4e2a<code>successful<\/code> array \u548c\u4e00\u4e2a <code>fail<\/code> array\uff0c\u5206\u522b\u5305\u542b\u6210\u529f\u548c\u5931\u8d25\u7684\u8ba2\u5355\u53f7\u7801\u3002\u53ef\u7ed3\u679c\u662f\u8fd4\u56de\u7a7a\u7684 array \u3002\u6211 JS \u8fd8\u6ca1\u6709\u597d\u597d\u5b66\uff0c\u53ea\u662f\u8fb9\u505a\u8fb9\u67e5\uff0c\u54ea\u4f4d\u76d8\u53cb\u6307\u70b9\u4e00\u4e0b \ud83d\ude42<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>21<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1779254\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lonelinsky <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             (\u4f60\u8981\u4e0d\u5148\u7814\u7a76\u4e0b Python3 \u7684 asyncio\uff0c\u7b49\u7814\u7a76\u5b8c\u56de\u6765\u518d\u770b\uff0c\u53ef\u80fd\u5c31\u77e5\u9053\u95ee\u9898\u6240\u5728\u4e86 \ud83d\ude42                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779255\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jybox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Promise.all \u6216 Promise.allSettled                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779256\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Marven <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 async await                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779257\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rabbbit <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             fetch(`https:\/\/jsonplaceholder.typicode.com\/posts\/${arg}`, {method: &#8216;GET&#8217;})<br \/>-&gt;<br \/>return fetch(`https:\/\/jsonplaceholder.typicode.com\/posts\/${arg}`, { method: &#8216;GET&#8217; })<\/p>\n<p>for (i = 0; i &lt; ordersID.length; i++) {makeRequest(ordersID[i]); console.log(successful, fail)};<br \/>-&gt;<\/p>\n<p> for (i = 0; i &lt; ordersID.length; i++) {<br \/> \u3000 makeRequest(ordersID[i]).then(() =&gt; {<br \/> \u3000\u3000 console.log(successful, fail);<br \/> \u3000});<br \/> };<\/p>\n<p>\u76f8\u5173\u77e5\u8bc6\u70b9 <br \/>Promise<br \/>event loop<br \/>macrotask \u548c microtask                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779258\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sudoy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @rabbbit @Marven @jybox @lonelinsky \u54c7\uff01\u4f60\u4eec\u592a\u7ed9\u529b\uff0c\u7ed9\u4f60\u4eec\u70b9\u8d5e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779259\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : azcvcza <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7684 console.log \u6700\u597d\u90fd\u4e22\u5728\u548c then \u540c\u4e00\u4e2a\u62ec\u53f7\u91cc; \u9996\u5148 JS \u81ea\u9876\u5411\u4e0b\u6267\u884c\u4ee3\u7801\uff0c \u5982\u679c\u78b0\u5230 setTimeout\uff0c\u6216\u8005 promise \u5c31\u628a\u4ed6\u585e\u5230\u4e8b\u4ef6\u961f\u5217\u5c3e\uff0c\u4e0b\u4e00\u4e2a\u5468\u671f\u518d\u6267\u884c\uff1b\u4f60\u8fd9\u91cc console.log,\u5fc5\u7136\u62ff\u4e0d\u5230\u8bf7\u6c42\u7684\u6570\u636e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779260\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CyHstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6d4f\u89c8\u5668\u6267\u884c js \u662f\u6709\u987a\u5e8f\u7684\uff0c\u81ea\u9876\u5411\u4e0b\u6267\u884c\u6240\u6709\u7684\u540c\u6b65 js\uff0c\u7136\u540e\u518d\u6267\u884c\u5f02\u6b65\u56de\u8c03\u3002\u6240\u4ee5\u4f60\u5148\u7528\u4e00\u4e2a for \u5faa\u73af\u53bb\u8c03\u7528 fetch\uff0c\u7136\u540e\u5c31 console \u4e86\u7ed3\u679c\uff0c\u90a3\u4e48\u6b64\u65f6 fetch \u8fd8\u6ca1\u6709\u8bf7\u6c42\u56de\u6765\uff0c\u662f\u4e00\u4e2a\u5f02\u6b65\u7684\uff0c\u6240\u4ee5 console \u6253\u5370\u51fa\u6765\u7684\u5c31\u662f\u7a7a\u7684\uff0c\u8981\u5728 fetch \u7684\u56de\u8c03\u51fd\u6570\u91cc\u6253\u5370\uff0c\u6216\u8005\uff0c\u7528 async await \u963b\u585e\u5f02\u6b65\u8bf7\u6c42\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779261\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sayitagain <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             js \u8bf7\u6c42\u5e76\u4e0d\u4f1a\u7b49\u5230\u8bf7\u6c42\u7ed3\u675f\u624d\u5f80\u4e0b\u8d70,\u6709\u53ef\u80fd\u8fd9\u6b21\u8bf7\u6c42\u53d1\u51fa\u53bb\u8fd8\u6ca1\u6536\u5230\u54cd\u5e94\u503c\u5c31\u5df2\u7ecf\u6267\u884c console.log(successful, fail)\u4e86&#8230;\u8981\u4e48\u628a console.log(successful, fail)\u653e\u5728 then \u91cc,\u8981\u4e48\u628a\u8bf7\u6c42\u8bbe\u7f6e\u4e3a\u540c\u6b65&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779262\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whatCanIDoForYou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/504J5BO2-198.png\" alt=\"Javascript \u4ee3\u7801\u6267\u884c\u5148\u540e\u987a\u5e8f\u95ee\u9898\"> \u60f3\u5b66\u4e60 \u4f60\u600e\u4e48\u7c98\u8d34\u4ee3\u7801\u7684\u3002\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779263\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             `Promise.allSettled()` \u80fd\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\u554a\uff0c\u8bf7\u6c42\u7ed3\u679c\u81ea\u5e26 `status`\uff0c\u6839\u636e\u5b83\u5224\u65ad\u6210\u529f\u5931\u8d25\u5c31\u597d\uff0c\u6216\u8005\u76f4\u63a5\u6839\u636e\u6709\u6ca1\u6709 `value` \u6216 `reason` \u5224\u65ad\u4e5f\u884c\u3002\u4f60\u8fd9\u79cd\u5c5e\u4e8e\u4e32\u884c\u7684\u7ee7\u53d1\u8bf7\u6c42\u6a21\u5f0f\uff0c`async..await` \u8bed\u6cd5\u4f1a\u66f4\u9002\u5408\u8fd9\u4e2a\u573a\u666f\uff0c\u5199\u8d77\u6765\u65f6\u5e8f\u66f4\u76f4\u89c2\uff0c\u4e0d\u7136\u50cf\u8fd9\u6837\u5bb9\u6613\u5c31\u628a `Promise` \u4f18\u96c5\u7684\u94fe\u5f0f\u8c03\u7528\u6d3b\u751f\u751f\u5199\u6210\u300c\u56de\u8c03\u5957\u5a03\u300d\u3002\u6e29\u99a8\u63d0\u793a\uff1a\u5efa\u8bae `fetch()` \u53ef\u4ee5\u5c01\u88c5\u4e00\u4e0b\u3002<br \/>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Operators\/await                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779264\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Shy07 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             JS \u4e00\u822c\u63a8\u8350\u51fd\u6570\u5f0f\u7684\u5199\u6cd5\uff1a<\/p>\n<p>const promises = orderID.map(makeRequest)<br \/>const result = await Promise.all(promises)<br \/>const successfull = result.filter(val =&gt; res.status === &#8216;ok&#8217;)<br \/>const fail = result.filter(val =&gt; res.status !== &#8216;ok&#8217;)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779265\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Shy07 `status` \u7684\u503c\u8981\u4e48 `fulfilled`\uff0c\u8981\u4e48 `rejected`\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779266\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Shy07 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JayLin1011 \u4e2a\u4eba\u6bd4\u8f83\u503e\u5411\u5728 makeRequest \u91cc\u9884\u5148\u5904\u7406\u4e00\u4e0b\u8bf7\u6c42\u7ed3\u679c\uff0c\u6bd4\u5982\u8fd4\u56de { status: string, arg: any, err: Error }                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779267\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sudoy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd8\u662f V \u53cb\u7ed9\u529b\uff0c\u8fd9\u4e48\u591a\u56de\u7b54\uff01\u591a\u8c22\u5404\u4f4d\u5566\uff01<\/p>\n<p>@whatCanIDoForYou <br \/>&gt; \u60f3\u5b66\u4e60 \u4f60\u600e\u4e48\u7c98\u8d34\u4ee3\u7801\u7684\u3002\u3002\u3002\u3002<\/p>\n<p>V \u7ad9\u53d1\u5e16\u7684\u65f6\u5019\u652f\u6301 markdown \u8bed\u6cd5\u7684\uff0c \u4f46\u662f\u56de\u590d\u5e16\u5b50\u7684\u65f6\u5019\u4f3c\u4e4e\u4e0d\u652f\u6301                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779268\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Shy07 \u3002\u3002\u4e0d\u662f\u8bf7\u6c42\u5904\u7406\u7684\u95ee\u9898\uff0c`Promise.all()` \u7684\u8fd4\u56de\u503c\u683c\u5f0f\u662f\u56fa\u5b9a\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779269\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jones2000 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5 js \u88f8\u5199\u4e00\u4e2a\u4e0b\u8f7d\u961f\u5217\uff0c\u6279\u91cf\u4e0b\u8f7d\u4e0d\u5c31\u53ef\u4ee5\u4e86\u3002\u5982\u679c\u8fc1\u79fb\u5230\u5176\u4ed6\u5e73\u53f0\uff0c\u6362\u6210\u591a\u7ebf\u7a0b\u4e0b\u8f7d\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>&#8220;`javascript<br \/>function OnFinished(aryResult)<br \/> {<br \/> console.log(&#8220;\u4e0b\u8f7d\u5b8c\u6210\u4e86&#8221;, aryResult)<br \/> }<\/p>\n<p>var download=new JSDownload();<br \/>download.FinishCallback=OnFinished;<br \/>var downloadList=<br \/> [<br \/> {Url:&#8221;https:\/\/abc&#8221;}, <br \/> {Url:&#8221;https:\/\/abc1&#8243;},<br \/> {Url:&#8221;https:\/\/abc2&#8243;}<br \/> ];<br \/> download.SetDownload(downloadList);<br \/> download.Start();<br \/>&#8220;`<\/p>\n<p> &#8220;`javascript<br \/>\/\/\u6279\u91cf\u4e0b\u8f7d<br \/> function JSDownload()<br \/> {<br \/> this.DownloadData; <br \/> \/*<br \/> Key:url <br \/> Value: <br \/> { <br \/> Status: \u72b6\u6001 0=\u7a7a\u95f2 1=\u4e0b\u8f7d\u4e2d, 20=\u4e0b\u8f7d\u6210\u529f 30=\u5931\u8d25 , <br \/> Message:\u9519\u8bef\u4fe1\u606f, <br \/> ProcSuccess: \u5355\u4e2a\u6570\u636e\u5230\u8fbe\u56de\u8c03(\u4e0d\u5904\u7406\u5c31 null)<br \/> ProcFailed: \u5355\u4e2a\u6570\u636e\u5931\u8d25\u56de\u8c03(\u4e0d\u5904\u7406\u5c31 null) <br \/> RecvData: \u63a5\u6536\u5230\u7684\u6570\u636e<br \/> }<br \/> *\/<br \/> this.FinishCallback; \/\/\u5168\u90e8\u4e0b\u8f7d\u5b8c\u56de\u8c03<\/p>\n<p> \/\/\u8bbe\u7f6e\u6279\u91cf\u4e0b\u8f7d\u5730\u5740<br \/> this.SetDownload=function(aryDownload)<br \/> {<br \/> this.DownloadData=new Map();<br \/> for(var i in aryDownload)<br \/> {<br \/> var item=aryDownload[i];<br \/> if (this.DownloadData.has(item.Url)) continue;<\/p>\n<p> var downItem={Url:item.Url, ProcSuccess:item.ProcSuccess, ProcFailed:item.ProcFailed , Status:0 };<br \/> this.DownloadData.set(downItem.Url,downItem);<br \/> }<br \/> }<\/p>\n<p> \/\/\u662f\u5426\u5168\u90e8\u4e0b\u8f7d\u5b8c\u6210<br \/> this.OnFinished=function()<br \/> {<br \/> for (var item of this.DownloadData) \/\/\u904d\u5386\u4e0b\u8f7d\u961f\u5217 \u662f\u5426\u90fd\u4e0b\u8f7d\u5b8c\u4e86<br \/> {<br \/> if (item[1].Status==20 || item[1].Status==30) continue;<\/p>\n<p> return;<br \/> }<\/p>\n<p> if (this.FinishCallback) \/\/\u901a\u77e5\u56de\u8c03 \u6570\u636e\u90fd\u4e0b\u8f7d\u5b8c\u4e86<br \/> {<br \/> var aryResult=[];<br \/> for (var item of this.DownloadData)<br \/> {<br \/> var downloadItem=item[1];<br \/> if (downloadItem.Status==20)<br \/> aryResult.push({Url:downloadItem.Url, Success:true, Data:downloadItem.RecvData});<br \/> else <br \/> aryResult.push({Url:downloadItem.Url,Success:false});<br \/> }<\/p>\n<p> this.FinishCallback(aryResult);<br \/> }<br \/> }<\/p>\n<p> \/\/\u5f00\u59cb\u4e0b\u8f7d<br \/> this.Start=function()<br \/> {<br \/> var self=this;<br \/> for (var item of this.DownloadData)<br \/> {<br \/> console.log(&#8216;[JSDownload::Start] start dowloand &#8216;, item[0]);<br \/> this.AjaxDownload(item[1]);<\/p>\n<p> }<br \/> }<\/p>\n<p> this.AjaxDownload=function(item)<br \/> {<br \/> var self=this;<br \/> $.ajax({<br \/> url: item.Url,<br \/> type:&#8221;get&#8221;,<br \/> dataType: &#8220;json&#8221;,<br \/> async:true,<br \/> success: function (data)<br \/> {<br \/> if (item.ProcSuccess) item.ProcSuccess(data, self);<br \/> item.RecvData=data;<br \/> item.Status = 20;<br \/> self.OnFinished();<br \/> },<br \/> error:function(jqXHR, textStatus, errorThrown)<br \/> {<br \/> if (item.ProcFailed) item.ProcFailed(jqXHR,self);<br \/> item.Status = 30;<br \/> self.OnFinished();<br \/> }<br \/> });<br \/> item.Status=1;<br \/> }<br \/> }<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779270\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Shy07 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JayLin1011 <br \/>`Promise.all()` \u8fd4\u56de\u503c\u662f\u51fd\u6570\u7684\u8fd4\u56de\u503c<br \/>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Promise\/all<\/p>\n<p>`Promise.allSettled()` \u624d\u662f\u56fa\u5b9a\u7684<br \/>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Promise\/allSettled                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779271\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Shy07 \u5bf9\u3002\u4f46\u6211\u7684 `promises` \u4e0d\u4f1a\u5168\u90e8\u6210\u529f\uff0c\u6211\u8fd8\u662f\u9009\u62e9 `Promise.allSettled()`\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779272\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : oukichi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3a\u5565\u8981 then \u91cc\u9762\u5957 then \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779273\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : linZ <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u4ee5 resolve(promise)\u7684\uff0c\u7136\u540e\u8bd5\u4e00\u4e0b async await \u5440\uff0c\u770b\u4e0b\u8c01\u7ed9\u4f60\u5199\u4e2a async await \u7248\u672c\u7684\uff0c\u4f60\u5c31\u660e\u767d\u5566                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1779274\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pomelotea2009 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u641c\uff1ajs async all                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Javascript \u4ee3\u7801\u6267\u884c\u5148\u540e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/106998"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=106998"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/106998\/revisions"}],"predecessor-version":[{"id":107000,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/106998\/revisions\/107000"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=106998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=106998"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=106998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}