{"id":52961,"date":"2024-12-03T08:16:40","date_gmt":"2024-12-03T00:16:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52961\/"},"modified":"2024-12-03T08:16:40","modified_gmt":"2024-12-03T00:16:40","slug":"javascript%e5%bc%82%e6%ad%a5%e6%93%8d%e4%bd%9c%e8%bf%94%e5%9b%9epromise%e5%af%b9%e8%b1%a1%e8%80%8c%e4%b8%8d%e6%98%af%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52961\/","title":{"rendered":"JavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>JavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241125\/17325014956743dff72363d.jpg\" class=\"aligncenter\" title=\"JavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"JavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u89e3\u51b3\u201c\u83b7\u5f97\u5b57\u7b26\u4e32\u4f46 return \u503c\u4e3a [object promise]\u201d\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u5728 javascript \u4e2d\uff0c\u9047\u5230 suchproblem \u662f\u56e0\u4e3a\u5f02\u6b65\u5904\u7406\u5bfc\u81f4\u7684\u3002\u5f53\u4f7f\u7528 await \u5173\u952e\u5b57\u83b7\u53d6\u5f02\u6b65\u8bf7\u6c42\u7684\u7ed3\u679c\u65f6\uff0cjavascript \u5b9e\u9645\u4e0a\u8fd4\u56de\u7684\u662f\u4e00\u4e2a promise \u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u503c\u3002<\/p>\n<p>\u5728\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0cinto \u51fd\u6570\u5f02\u6b65\u83b7\u53d6\u6570\u636e\u5e76\u8fd4\u56de\u4e00\u4e2a promise\u3002\u7136\u800c\uff0cintotext \u51fd\u6570\u5374\u76f4\u63a5\u8fd4\u56de\u4e86\u8fd9\u4e2a promise\uff0c\u800c\u4e0d\u662f\u7b49\u5f85\u5b83\u7684\u7ed3\u679c\u3002\u56e0\u6b64\uff0cconsole.log(getit.join(&#8216;,&#8217;)) \u53ea\u80fd\u6253\u5370\u51fa &#8220;[object promise]&#8221;\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u5728 intotext \u51fd\u6570\u4e2d\u4f7f\u7528 then \u65b9\u6cd5\u6765\u83b7\u53d6 promise \u7684\u7ed3\u679c\uff0c\u7136\u540e\u5728\u56de\u8c03\u4e2d\u5904\u7406\u6570\u636e\uff1a<\/p>\n<pre>const intoText = async (ids) =&gt; {\n  if (ids) {\n    let getit = await into(ids);\n    return getit.join(',');\n  }\n};\n\nintoText().then((txt) =&gt; {\n  \/\/ \u5c06\u5b57\u7b26\u4e32\u5206\u914d\u7ed9\u6240\u9700\u7684\u53d8\u91cf\u6216\u663e\u793a\u5728\u754c\u9762\u4e0a\n  xxx.xxx = txt;\n});<\/pre>\n<p>\u8fd9\u6837\uff0cintotext \u51fd\u6570\u8fd4\u56de\u7684\u4e0d\u518d\u662f\u4e00\u4e2a promise\uff0c\u800c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u5728\u56de\u8c03\u4e2d\u81ea\u7531\u4f7f\u7528\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aJavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5c0f\u7a0b\u5e8f\u8f6e\u64ad\u56fe\u5982\u4f55\u5b9e\u73b0\u81ea\u9002\u5e94\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300aJavaScript\u5f02\u6b65\u64cd\u4f5c\u8fd4\u56dePromise\u5bf9\u8c61\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u600e\u4e48\u529e\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 \u89e3\u51b3\u201c\u83b7\u5f97\u5b57\u7b26\u4e32\u4f46 return \u503c\u4e3a [object promise]\u201d\u7684\u95ee\u9898 \u5728 javascript \u4e2d\uff0c\u9047\u5230 suchproblem \u662f\u56e0\u4e3a\u5f02\u6b65\u5904\u7406\u5bfc\u81f4\u7684\u3002\u5f53\u4f7f\u7528 await \u5173\u952e\u5b57\u83b7\u53d6\u5f02\u6b65\u8bf7\u6c42\u7684\u7ed3\u679c\u65f6\uff0cjavascript \u5b9e\u9645\u4e0a\u8fd4\u56de\u7684\u662f\u4e00\u4e2a promise \u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u503c\u3002 \u5728\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0cinto \u51fd\u6570\u5f02\u6b65\u83b7\u53d6\u6570\u636e\u5e76\u8fd4\u56de\u4e00\u4e2a promise\u3002\u7136\u800c\uff0cintotext \u51fd\u6570\u5374\u76f4\u63a5\u8fd4\u56de\u4e86\u8fd9\u4e2a promise\uff0c\u800c\u4e0d\u662f\u7b49\u5f85\u5b83\u7684\u7ed3\u679c\u3002\u56e0\u6b64\uff0cconsole.log(getit.join(&#8216;,&#8217;)) \u53ea\u80fd\u6253\u5370\u51fa &#8220;[object promise]&#8221;\u3002 \u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u5728 intotext \u51fd\u6570\u4e2d\u4f7f\u7528 then \u65b9\u6cd5\u6765\u83b7\u53d6 promise \u7684\u7ed3\u679c\uff0c\u7136\u540e\u5728\u56de\u8c03\u4e2d\u5904\u7406\u6570\u636e\uff1a const intoText = async (ids) =&gt; { if (ids) { let getit = await into(ids); return getit.join(&#8216;,&#8217;); } }; intoText().then((txt) =&gt; { \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52961","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52961"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52961\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}