{"id":208097,"date":"2025-07-08T16:41:57","date_gmt":"2025-07-08T08:41:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208097\/"},"modified":"2025-07-08T16:41:57","modified_gmt":"2025-07-08T08:41:57","slug":"%e5%88%b7%e6%96%b0%e5%90%8e%e5%9c%b0%e5%9b%be%e4%b8%ad%e7%9a%84%e5%80%bc%e5%8f%91%e7%94%9f%e5%8f%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208097\/","title":{"rendered":"\u5237\u65b0\u540e\u5730\u56fe\u4e2d\u7684\u503c\u53d1\u751f\u53d8\u5316"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5237\u65b0\u540e\u5730\u56fe\u4e2d\u7684\u503c\u53d1\u751f\u53d8\u5316<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-28 23:09:27<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5728Golang\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300a\u5237\u65b0\u540e\u5730\u56fe\u4e2d\u7684\u503c\u53d1\u751f\u53d8\u5316\u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u521b\u5efa\u4e00\u4e2a\u5728\u8c03\u7528\u9875\u9762\u65f6\u8bb0\u4f4f\u5176\u503c\u7684\u5730\u56fe\u3002\u6211\u5728\u51fd\u6570\u5916\u90e8\u58f0\u660e\u4e86\u5b83\uff0c\u56e0\u6b64\u5b83\u4f1a\u4fdd\u6301\u4e0d\u53d8\uff0c\u4f46\u5f53\u8c03\u7528\u9875\u9762\u65f6\uff0c\u6620\u5c04\u4ecd\u7136\u521d\u59cb\u5316\u4e3a\u9ed8\u8ba4=t \u503c\u3002\u6211\u600e\u6837\u624d\u80fd\u8ba9\u5b83\u8bb0\u4f4f\u5b83\u7684\u503c\uff1f<\/p>\n<pre>var rememberExpand =  make(map[int]bool{})\n\nfunc (c *CollapsibleWithOption) Layout(gtx layout.Context, header, body func(C) D, more func(C), wallet_ID int) layout.Dimensions {\n    fmt.Println(rememberExpand)\n    for c.button.Clicked() {\n        c.isExpanded = !c.isExpanded\n    }\n\n    rememberExpand[wallet_ID] = c.isExpanded\n    fmt.Println(rememberExpand)\n\n    icon := c.collapsedIcon\n    if c.isExpanded {\n        icon = c.expandedIcon\n    }\n\n\n                        \n                    )\n                })\n            }),\n            layout.Rigid(func(gtx C) D {\n                if rememberExpand[wallet_ID] {\n                    return body(gtx)\n                }\n                return D{}\n            }),\n        )\n    })\n}<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u5c1d\u8bd5\u5c06\u5730\u56fe\u5b9a\u4e49\u4e3a `var rememberexpand map[int]bool\u3002<\/p>\n<p>\u7136\u800c\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u65b0\u95ee\u9898\u3002\u7b2c\u4e00\u6b21\u5f15\u7528\u6b64\u5730\u56fe\u65f6\uff0c\u5b83\u5c06\u662f <code>nil<\/code>\uff0c\u56e0\u4e3a\u5b83\u5c1a\u672a\u5236\u4f5c\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u5730\u56fe\u662f\u5426\u7b49\u4e8e <code>nil<\/code> \u6765\u76f8\u5f53\u8f7b\u677e\u5730\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u5982\u679c\u662f\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u65b0\u5730\u56fe\uff1a<\/p>\n<pre>var rememberExpand map[int]bool\n\nfunc (c *CollapsibleWithOption) Layout(gtx layout.Context, header, body func(C) D, more func(C), wallet_ID int) layout.Dimensions {\n    if rememberExpand == nil { \/\/ Check if the map has been initialized yet\n      rememberExpand = make(map[int]bool) \/\/ If not, create a new map\n    }\n\n    for c.button.Clicked() {\n        c.isExpanded = !c.isExpanded\n    }\n\n    rememberExpand[wallet_ID] = c.isExpanded\n    fmt.Println(rememberExpand)\n\n    icon := c.collapsedIcon\n    if c.isExpanded {\n        icon = c.expandedIcon\n    }\n\n\n                        \n                    )\n                })\n            }),\n            layout.Rigid(func(gtx C) D {\n                if rememberExpand[wallet_ID] {\n                    return body(gtx)\n                }\n                return D{}\n            }),\n        )\n    })\n}<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5237\u65b0\u540e\u5730\u56fe\u4e2d\u7684\u503c\u53d1\u751f\u53d8\u5316\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03Golang\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-208097","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208097"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208097\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}