{"id":5510,"date":"2023-01-05T12:52:22","date_gmt":"2023-01-05T04:52:22","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5510"},"modified":"2023-01-05T12:52:22","modified_gmt":"2023-01-05T04:52:22","slug":"%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87map%e5%b0%8d%e8%b1%a1%e8%bd%89%e6%8f%9b%e7%82%ba%e6%8c%87%e5%ae%9a%e6%a0%bc%e5%bc%8f%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87map%e5%b0%8d%e8%b1%a1%e8%bd%89%e6%8f%9b%e7%82%ba%e6%8c%87%e5%ae%9a%e6%a0%bc%e5%bc%8f%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2\/","title":{"rendered":"\u4f7f\u7528TypeScriptMap\u5c07Map\u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Map, toQueryString\"><\/p>\n<h1>\u4f7f\u7528 TypeScript Map \u5c07 Map \u5bf9\u8c61\u8f6c\u5316\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32(toQueryString)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7279\u6027\uff0c\u4f7f\u5f97\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u958b\u767c\u51fa\u66f4\u9ad8\u8cea\u91cf\u7684\u4ee3\u78bc\u3002\u5176\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u7279\u6027\u5c31\u662f Map\uff0c\u5b83\u53ef\u4ee5\u5c07\u4e00\u500b\u5c0d\u8c61\u8f49\u63db\u70ba\u4e00\u500b Map \u5c0d\u8c61\uff0c\u4e26\u4e14\u53ef\u4ee5\u5c07 Map \u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u9019\u500b\u529f\u80fd\u5c31\u662f toQueryString\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f Map \u5c0d\u8c61\uff1f<\/h2>\n<p>Map \u5c0d\u8c61\u662f\u4e00\u7a2e JavaScript \u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u5c07\u4e00\u500b\u5c0d\u8c61\u8f49\u63db\u70ba\u4e00\u500b Map \u5c0d\u8c61\uff0c\u4e26\u4e14\u53ef\u4ee5\u5c0d Map \u5c0d\u8c61\u9032\u884c\u64cd\u4f5c\uff0c\u4f8b\u5982\u6dfb\u52a0\u3001\u522a\u9664\u3001\u4fee\u6539\u7b49\u3002Map \u5c0d\u8c61\u7684\u512a\u9ede\u5728\u65bc\u5b83\u53ef\u4ee5\u5c07\u4e00\u500b\u5c0d\u8c61\u8f49\u63db\u70ba\u4e00\u500b Map \u5c0d\u8c61\uff0c\u4e26\u4e14\u53ef\u4ee5\u5c0d Map \u5c0d\u8c61\u9032\u884c\u64cd\u4f5c\uff0c\u800c\u4e0d\u9700\u8981\u5c0d\u539f\u59cb\u5c0d\u8c61\u9032\u884c\u4efb\u4f55\u4fee\u6539\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f toQueryString\uff1f<\/h2>\n<p>toQueryString \u662f\u4e00\u500b TypeScript \u7684\u51fd\u6578\uff0c\u5b83\u53ef\u4ee5\u5c07\u4e00\u500b Map \u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet map = new Map();\nmap.set('name', 'John');\nmap.set('age', '20');\n\nlet queryString = toQueryString(map);\n\/\/ queryString = \"name=John&age=20\"\n<\/pre>\n<p>toQueryString \u51fd\u6578\u53ef\u4ee5\u5c07\u4e00\u500b Map \u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u9019\u500b\u5b57\u7b26\u4e32\u53ef\u4ee5\u7528\u65bc URL \u67e5\u8a62\u53c3\u6578\uff0c\u6216\u8005\u662f\u5176\u4ed6\u9700\u8981\u5c07\u5c0d\u8c61\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\u7684\u5730\u65b9\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 toQueryString\uff1f<\/h2>\n<p>\u4f7f\u7528 toQueryString \u51fd\u6578\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u50b3\u5165\u4e00\u500b Map \u5c0d\u8c61\uff0c\u5c31\u53ef\u4ee5\u5c07\u5176\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet map = new Map();\nmap.set('name', 'John');\nmap.set('age', '20');\n\nlet queryString = toQueryString(map);\n\/\/ queryString = \"name=John&age=20\"\n<\/pre>\n<p>toQueryString \u51fd\u6578\u53ef\u4ee5\u5c07\u4e00\u500b Map \u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u9019\u500b\u5b57\u7b26\u4e32\u53ef\u4ee5\u7528\u65bc URL \u67e5\u8a62\u53c3\u6578\uff0c\u6216\u8005\u662f\u5176\u4ed6\u9700\u8981\u5c07\u5c0d\u8c61\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\u7684\u5730\u65b9\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript \u63d0\u4f9b\u4e86\u4e00\u500b\u975e\u5e38\u6709\u7528\u7684\u51fd\u6578 toQueryString\uff0c\u5b83\u53ef\u4ee5\u5c07\u4e00\u500b Map \u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u9019\u500b\u5b57\u7b26\u4e32\u53ef\u4ee5\u7528\u65bc URL \u67e5\u8a62\u53c3\u6578\uff0c\u6216\u8005\u662f\u5176\u4ed6\u9700\u8981\u5c07\u5c0d\u8c61\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\u7684\u5730\u65b9\u3002\u4f7f\u7528 toQueryString \u51fd\u6578\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u50b3\u5165\u4e00\u500b Map \u5c0d\u8c61\uff0c\u5c31\u53ef\u4ee5\u5c07\u5176\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u66f4\u591a\u8cc7\u8a0a<\/h2>\n<p>\u5982\u679c\u4f60\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u95dc\u65bc TypeScript Map \u5c0d\u8c61\u548c toQueryString \u51fd\u6578\u7684\u8cc7\u8a0a\uff0c\u53ef\u4ee5\u53c3\u8003\u4ee5\u4e0b\u8cc7\u6e90\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/advanced-types.html\" target=\"_blank\" rel=\"noopener\">TypeScript \u624b\u518a &#8211; \u9032\u968e\u985e\u578b<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Map\" target=\"_blank\" rel=\"noopener\">MDN &#8211; Map \u5c0d\u8c61<\/a><\/li>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/utility-types.html#tostringmap\" target=\"_blank\" rel=\"noopener\">TypeScript \u624b\u518a &#8211; toQueryString \u51fd\u6578<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5c07Map\u5c0d\u8c61\u8f49\u63db\u70ba\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u4ee5\u4fbf\u5c0d\u61c9\u61c9\u7528\u7a0b\u5e8f\u4e2d\u7684\u67e5\u8a62\u5b57\u7b26\u4e32\u3002\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Map\u5c0d\u8c61\u7684toQueryString()\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u8655\u7406\u67e5\u8a62\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5510","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1qS","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5510"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5510\/revisions"}],"predecessor-version":[{"id":5511,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5510\/revisions\/5511"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}