{"id":33311,"date":"2024-11-25T12:22:42","date_gmt":"2024-11-25T04:22:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33311\/"},"modified":"2024-11-25T12:22:42","modified_gmt":"2024-11-25T04:22:42","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b9%8bpicker-%e6%95%b0%e6%8d%ae%e6%98%af-object-array","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33311\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u4e4bpicker \u6570\u636e\u662f Object Array"},"content":{"rendered":"<p>\u6211\u4eec\u5728\u64cd\u4f5c&nbsp;picker&nbsp;\u7ec4\u4ef6\u7684\u65f6\u5019 \u53ef\u80fd\u4f1a\u6709\u7591\u60d1\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6e32\u67d3\u95ee\u9898\uff0c\u6216\u8005\u6211\u5c31\u662f\u60f3\u53d6\u4e2d\u6587\u7684\u503c\uff0c\u600e\u4e48\u529e\uff1f<\/p>\n<p>\u89c6\u56fe\u5c42<\/p>\n<pre>&lt;view&gt;\u6570\u636e\u662fjson\u7684\uff0c\u76f4\u63a5\u5c55\u793a&lt;\/view&gt;\npicker\u4f7f\u7528\u8bf4\u660e\uff1a\n\n&lt;picker&gt;\n&nbsp;&nbsp;\u5f53\u524d\u9009\u62e9&nbsp;{{school[currentSchool].valuess}}\n&nbsp;&nbsp;\n&lt;\/picker&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u903b\u8f91\u5c42<\/p>\n<pre>page({\n&nbsp;&nbsp;&nbsp;&nbsp;data:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;school:&nbsp;[\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\"isNewRecord\":false,\"id\":\"2\",\"keyss\":\"school\",\"valuess\":\"\u6e56\u5357\u5c0f\u5b66\"},\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\"isNewRecord\":false,\"id\":\"3\",\"keyss\":\"school\",\"valuess\":\"\u5317\u4eac\u5c0f\u5b66\"}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentSchool:&nbsp;\"\"\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;handleChange(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(e)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c&nbsp;range\u662f\u4e00\u4e2a&nbsp;Object&nbsp;Array\u5f62\u5f0f\u7684\uff0c\u90a3\u8fd9\u91cc\u7684value\u5c31\u662f\u7d22\u5f15\u4e0b\u6807\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;currentVal&nbsp;=&nbsp;e.detail.value\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5bf9\u5e94\u7684\u4e2d\u6587\u662f\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;text&nbsp;=&nbsp;this.data.school[currentVal].valuess\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('\u4e2d\u6587--&amp;gt;',&nbsp;text)\n&nbsp;&nbsp;&nbsp;&nbsp;},\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u4f20\u5165\u7684\u662f\u4e00\u4e2a\u6570\u7ec4\u5bf9\u8c61 Object Array\u7c7b\u578b\uff0c \u90a3\u4e48\u6211\u4eec\u5728\u4f7f\u7528picker\u7ec4\u4ef6\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u8981\u5206\u6e05\uff0c\u8fd9\u4e9b\u5b57\u6bb5\u7684\u610f\u601d\uff0c\u4ee5\u53ca\u5982\u4f55\u53d6\u503c<\/p>\n<p>range-key \u662f\u544a\u8bc9\u6211\u4eec\uff0c\u5728\u6e32\u67d3\u7684\u65f6\u5019\uff0c\u662f\u4ee5\u4ec0\u4e48\u5b57\u6bb5\u53d6\u503c\uff0c\u4e0b\u9762\u5c31\u662f\u4e0d\u6307\u5b9a\u7684\u60c5\u51b5\uff0c\u5982\u679c\u662f\u5f88\u7b80\u5355\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<p>\u7c7b\u4f3c\uff1a school: [&#8220;\u4e2d\u6587&#8221;, &#8216;\u6570\u5b66&#8217;, &#8220;\u97f3\u4e50&#8221;]<\/p>\n<p>\u662f\u4e0d\u9700\u8981\u6307\u5b9a\u7684\uff0c\u5bf9\u4e8e\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u6307\u5b9a\u5b57\u6bb5\uff0c\u5fae\u4fe1\u4f1a\u81ea\u52a8\u5e2e\u6211\u4eec\u53bb\u8d4b\u503c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/871\/674\/542\/1592274646409492.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u4e4bpicker \u6570\u636e\u662f Object Array\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u4e4bpicker \u6570\u636e\u662f Object Array\u63d2\u56fe\" \/>\u4f5c\u8005\uff1a\u77e5\u4e86\u6e05\u8bed<\/p>\n<p>model:value=&#8221;{{currentSchool}}&#8221; &nbsp;\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u8fd9\u4e2a\uff0c\u4e3a\u4ec0\u4e48value\u524d\u9762\u7ed1\u5b9a\u4e86model<\/p>\n<p>\u56e0\u4e3a\u5fae\u4fe1\u4e0d\u662f\u53cc\u5411\u6570\u636e\u7ed1\u5b9a\u7684\uff0c\u5982\u679c\u5355\u7eaf\u7684\u5199 &nbsp;value=&#8221;{{\u5f53\u524d\u9009\u4e2d\u7684\u7d22\u5f15\u4e0b\u6807-currentSchool}}&#8221;<\/p>\n<p>\u903b\u8f91\u5c42\u7684currentSchool \u662f\u4e0d\u4f1a\u6709\u53d8\u5316\u7684\uff0c\u5fc5\u987b\u901a\u8fc7 bindchange\u4e8b\u4ef6\u53bb\u4fee\u6539 data\u4e2d\u7684\u6570\u636e, \u50cf\u4e0b\u9762\u8fd9\u6837<\/p>\n<pre>handleChange(e)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;this.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentSchool:&nbsp;e.detail.value\n&nbsp;&nbsp;&nbsp;&nbsp;})\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528model\u7684\u597d\u5904 \u5c31\u5728\u4e8e \u6211\u4eec\u4e0d\u9700\u8981\u5173\u7cfb\u8fd9\u4e2a\u8d4b\u503c\u64cd\u4f5c\uff0c\u53ea\u8981\u6211\u4eec\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u786e\u5b9a\uff0cdata\u4e2d\u7684 currentSchool\u5c31\u66f4\u65b0\u4e86\uff0c\u70b9\u51fb\u53d6\u6d88\u662f\u4e0d\u4f1a\u66f4\u65b0data\u4e2d\u7684\u6570\u636e\u7684<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/728\/235\/838\/1592274705636939.jpg\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u4e4bpicker \u6570\u636e\u662f Object Array\u63d2\u56fe1\" alt=\"\u5c0f\u7a0b\u5e8f\u4e4bpicker \u6570\u636e\u662f Object Array\u63d2\u56fe1\" \/><\/p>\n<p>\u6211\u4eec\u5728 handleChange\u4e2d\u7684 e.detail.value \u62ff\u5230\u7684\u503c\u4e5f\u5c31\u662f\u4e2a\u4e0b\u6807\uff0c\u5176\u5b9e\u6211\u4eec\u53ef\u80fd\u4f1a\u60f3\u8981text\u6587\u672c<\/p>\n<p>\u5c31\u76f4\u63a5\u50cf\u4e0a\u9762\u90a3\u6837\uff0c\u7528\u7d22\u5f15\u53bb\u53d6\u6e90\u6570\u636e\u4e2d\u7684 {} \u5bf9\u8c61\u5c5e\u6027<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u5c31\u662f\u5c06 school&#8211;schoolFilter\u53d8\u6210 [&#8220;\u6e56\u5357\u5c0f\u5b66&#8221;, &#8220;\u5317\u4eac\u5c0f\u5b66&#8221;] \u8fd9\u79cd\u7b80\u5355\u7ed3\u6784\uff0c\u90a3\u4e48e.detail.value \u83b7\u53d6\u7684\u5c31\u662f\u4e2d\u6587<\/p>\n<p>\u4f46\u662f\u8fd9\u79cd\u8981\u6c42\uff0cdata\u4e2d\u67092\u4e2a\u6570\u7ec4 schoolFilter&#8211;Array\u7c7b\u578b\u7684 \u548cschool&#8211;Object Array\u7c7b\u578b\u7684\uff0c picker\u4e2d\u7528 range = &#8220;{{schoolFilter}}&#8221;<\/p>\n<p>\u90a3\u4e48\u8981\u83b7\u53d6\u6e90\u6570\u636e\u7684\u5176\u4ed6\u5c5e\u6027\uff0c\u5c31\u5fc5\u987b\u904d\u5386school \u518d\u53d6\u503c<\/p>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<ul>\n<li>\n<p>\u4e0d\u60f3\u53bb\u5199bindchange\u66f4\u6539 data\u6570\u636e\uff0c\u5c31\u4f7f\u7528 model:<\/p>\n<\/li>\n<li>\n<p>picker \u5f00\u59cb\u6807\u7b7e\u548c\u7ed3\u675f\u6807\u7b7e \u4e2d\u5305\u88f9\u53ea\u662f\u9009\u62e9\u4ee5\u540e\u7684\u5185\u5bb9\uff0c\u4f60\u53ef\u4ee5\u968f\u610f\u53bb\u7ec4\u7ec7\u7528 text\u5448\u73b0\u6216\u8005 {{\u5185\u5bb9}}\u5448\u73b0 &nbsp;\u6216\u8005 view \u5448\u73b0 \u6216\u8005 input \u5448\u73b0 \u90fd\u53ef\u4ee5<\/p>\n<\/li>\n<li>\n<p>\u83b7\u53d6Object Array\u4e2d\u7684\u5176\u4ed6\u5b57\u6bb5\uff0c\u5982\u679c\u4e0d\u60f3\u8fc7\u6ee4\u6570\u636e\uff0c\u5c31\u4f7f\u7528 Object Array\u8fd9\u79cd\u7ed3\u6784\uff0c\u5c31\u901a\u8fc7\u7d22\u5f15\u4e0b\u73ed\u53bb\u8bbf\u95ee\uff0c\u4e0d\u9700\u8981\u5728data\u4e2d\u5efa2\u4e2a\u5b57\u6bb5<\/p>\n<\/li>\n<li>\n<p>\u53ea\u6709\u70b9\u51fb picker\u4e2d\u663e\u793a\u7684 \u3010\u786e\u5b9a\u3011\u6309\u94ae\uff0cpicker\u4e2d\u7684\u6570\u636e\u624d\u4f1a\u66f4\u65b0<\/p>\n<\/li>\n<\/ul>\n<p>\u63a8\u8350\u6559\u7a0b\uff1a\u300a\u300b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u4e4bpicker \u6570\u636e\u662f Object Array\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u5728\u64cd\u4f5c&nbsp;picker&nbsp;\u7ec4\u4ef6\u7684\u65f6\u5019 \u53ef\u80fd\u4f1a\u6709\u7591\u60d1\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6e32\u67d3\u95ee\u9898\uff0c\u6216\u8005\u6211\u5c31\u662f\u60f3\u53d6\u4e2d\u6587\u7684\u503c\uff0c\u600e\u4e48\u529e\uff1f \u89c6\u56fe\u5c42 &lt;view&gt;\u6570\u636e\u662fjson\u7684\uff0c\u76f4\u63a5\u5c55\u793a&lt;\/view&gt; picker\u4f7f\u7528\u8bf4\u660e\uff1a &lt;picker&gt; &nbsp;&nbsp;\u5f53\u524d\u9009\u62e9&nbsp;{{school[currentSchool].valuess}} &nbsp;&nbsp; &lt;\/picker&gt; \u767b\u5f55\u540e\u590d\u5236 \u903b\u8f91\u5c42 page({ &nbsp;&nbsp;&nbsp;&nbsp;data:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;school:&nbsp;[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&#8220;isNewRecord&#8221;:false,&#8221;id&#8221;:&#8221;2&#8243;,&#8221;keyss&#8221;:&#8221;school&#8221;,&#8221;valuess&#8221;:&#8221;\u6e56\u5357\u5c0f\u5b66&#8221;}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&#8220;isNewRecord&#8221;:false,&#8221;id&#8221;:&#8221;3&#8243;,&#8221;keyss&#8221;:&#8221;school&#8221;,&#8221;valuess&#8221;:&#8221;\u5317\u4eac\u5c0f\u5b66&#8221;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentSchool:&nbsp;&#8220;&#8221; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;handleChange(e)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(e) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5982\u679c&nbsp;range\u662f\u4e00\u4e2a&nbsp;Object&nbsp;Array\u5f62\u5f0f\u7684\uff0c\u90a3\u8fd9\u91cc\u7684value\u5c31\u662f\u7d22\u5f15\u4e0b\u6807 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;currentVal&nbsp;=&nbsp;e.detail.value &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5bf9\u5e94\u7684\u4e2d\u6587\u662f &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;text&nbsp;=&nbsp;this.data.school[currentVal].valuess &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(&#8216;\u4e2d\u6587&#8211;&amp;gt;&#8217;,&nbsp;text) &nbsp;&nbsp;&nbsp;&nbsp;}, }) \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91cc\uff0c\u6211\u4eec\u4f20\u5165\u7684\u662f\u4e00\u4e2a\u6570\u7ec4\u5bf9\u8c61 Object Array\u7c7b\u578b\uff0c \u90a3\u4e48\u6211\u4eec\u5728\u4f7f\u7528picker\u7ec4\u4ef6\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u8981\u5206\u6e05\uff0c\u8fd9\u4e9b\u5b57\u6bb5\u7684\u610f\u601d\uff0c\u4ee5\u53ca\u5982\u4f55\u53d6\u503c range-key \u662f\u544a\u8bc9\u6211\u4eec\uff0c\u5728\u6e32\u67d3\u7684\u65f6\u5019\uff0c\u662f\u4ee5\u4ec0\u4e48\u5b57\u6bb5\u53d6\u503c\uff0c\u4e0b\u9762\u5c31\u662f\u4e0d\u6307\u5b9a\u7684\u60c5\u51b5\uff0c\u5982\u679c\u662f\u5f88\u7b80\u5355\u7684\u6570\u636e\u7ed3\u6784 \u7c7b\u4f3c\uff1a school: [&#8220;\u4e2d\u6587&#8221;, &#8216;\u6570\u5b66&#8217;, &#8220;\u97f3\u4e50&#8221;] \u662f\u4e0d\u9700\u8981\u6307\u5b9a\u7684\uff0c\u5bf9\u4e8e\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u6307\u5b9a\u5b57\u6bb5\uff0c\u5fae\u4fe1\u4f1a\u81ea\u52a8\u5e2e\u6211\u4eec\u53bb\u8d4b\u503c \u4f5c\u8005\uff1a\u77e5\u4e86\u6e05\u8bed model:value=&#8221;{{currentSchool}}&#8221; &nbsp;\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u8fd9\u4e2a\uff0c\u4e3a\u4ec0\u4e48value\u524d\u9762\u7ed1\u5b9a\u4e86model \u56e0\u4e3a\u5fae\u4fe1\u4e0d\u662f\u53cc\u5411\u6570\u636e\u7ed1\u5b9a\u7684\uff0c\u5982\u679c\u5355\u7eaf\u7684\u5199 &nbsp;value=&#8221;{{\u5f53\u524d\u9009\u4e2d\u7684\u7d22\u5f15\u4e0b\u6807-currentSchool}}&#8221; \u903b\u8f91\u5c42\u7684currentSchool \u662f\u4e0d\u4f1a\u6709\u53d8\u5316\u7684\uff0c\u5fc5\u987b\u901a\u8fc7 bindchange\u4e8b\u4ef6\u53bb\u4fee\u6539 data\u4e2d\u7684\u6570\u636e, \u50cf\u4e0b\u9762\u8fd9\u6837 handleChange(e)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;this.setData({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentSchool:&nbsp;e.detail.value [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-33311","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33311","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=33311"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33311\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}