{"id":25369,"date":"2024-11-24T08:52:16","date_gmt":"2024-11-24T00:52:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25369\/"},"modified":"2024-11-24T08:52:16","modified_gmt":"2024-11-24T00:52:16","slug":"elementui-el-table-%e5%ad%90%e8%8a%82%e7%82%b9%e9%80%89%e4%b8%ad%e5%90%8e%e4%b8%ba%e4%bb%80%e4%b9%88%e6%b2%a1%e6%9c%89%e6%89%93%e5%8b%be%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25369\/","title":{"rendered":"ElementUI el-table \u5b50\u8282\u70b9\u9009\u4e2d\u540e\u4e3a\u4ec0\u4e48\u6ca1\u6709\u6253\u52fe\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173060012164269.jpg\" class=\"aligncenter\" title=\"ElementUI el-table \u5b50\u8282\u70b9\u9009\u4e2d\u540e\u4e3a\u4ec0\u4e48\u6ca1\u6709\u6253\u52fe\uff1f\u63d2\u56fe\" alt=\"ElementUI el-table \u5b50\u8282\u70b9\u9009\u4e2d\u540e\u4e3a\u4ec0\u4e48\u6ca1\u6709\u6253\u52fe\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>elementui el-table\u5b50\u8282\u70b9\u9009\u4e2d\u540e\u6ca1\u6709\u6253\u52fe\uff1f<\/strong><\/p>\n<p>\u5f53\u60a8\u5728elementui\u7684el-table\u4e2d\u9009\u62e9\u5b50\u8282\u70b9\u65f6\uff0c\u4f46\u6ca1\u6709\u51fa\u73b0\u6253\u52fe\u6548\u679c\uff0c\u53ef\u80fd\u662f\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a<\/p>\n<p>\u5728 <strong>element-ui<\/strong> \u7248\u672c <strong>2.15.7<\/strong> \u4e2d\u5b58\u5728\u8fd9\u4e2a\u95ee\u9898\uff0c\u5347\u7ea7\u5230\u6700\u65b0\u7248\u672c <strong>2.15.13<\/strong> \u5373\u53ef\u89e3\u51b3\u3002<\/p>\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u8bf7\u786e\u4fdd\u60a8\u9075\u5faa\u4e86\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5728\u8868\u683c\u4e2d\u6307\u5b9a <strong>selection-change<\/strong> \u4e8b\u4ef6\uff0c\u4ee5\u54cd\u5e94\u5b50\u8282\u70b9\u9009\u4e2d\u3002<\/li>\n<li>\u5728\u4e8b\u4ef6\u5904\u7406\u5668\u4e2d\uff0c\u4f7f\u7528 <strong>$refs.table.togglerowselection(row, true)<\/strong> \u65b9\u6cd5\u624b\u52a8\u52fe\u9009\u5b50\u8282\u70b9\u3002<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;el-table :data=\"customlist\" @selection-change=\"handleselectionchange\"&gt;\n  &lt;el-table-column type=\"selection\" width=\"55\" align=\"center\"&gt;&lt;\/el-table-column&gt;\n&lt;\/el-table&gt;\n\nhandleselectionchange(selection) {\n  selection.foreach((row) =&gt; {\n    this.$refs.table.togglerowselection(row, true);\n    if (row.children &amp;&amp; row.children.length) {\n      row.children.foreach((childrow) =&gt; {\n        this.$refs.table.togglerowselection(childrow, true);\n      });\n    }\n  });\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f <strong>tree-props<\/strong>\uff0c\u8bf7\u786e\u4fdd\u4e3a <strong>children<\/strong> \u6307\u5b9a\u4e00\u4e2a\u552f\u4e00\u7684\u5c5e\u6027\uff0c\u5426\u5219\u65e0\u6cd5\u6b63\u786e\u9009\u62e9\u548c\u52fe\u9009\u5b50\u8282\u70b9\u3002<\/p>\n<pre>&lt;el-table :data=\"customList\" @selection-change=\"handleSelectionChange\" :tree-props=\"{children: 'children'}\"&gt;\n  &lt;el-table-column type=\"selection\" width=\"55\" align=\"center\"&gt;&lt;\/el-table-column&gt;\n&lt;\/el-table&gt;\n\nhandleSelectionChange(selection) {\n  selection.forEach((row) =&gt; {\n    this.$refs.table.toggleRowSelection(row, true);\n    if (row.children &amp;&amp; row.children.length) {\n      row.children.forEach((childRow) =&gt; {\n        this.$refs.table.toggleRowSelection(childRow, true);\n      });\n    }\n  });\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u6309\u7167\u8981\u6c42\u8fdb\u884c\u540e\uff0c\u5c31\u53ef\u4ee5\u4e3aelementui el-table\u4e2d\u7684\u5b50\u8282\u70b9\u9009\u53d6\u884c\u4e3a\u663e\u793a\u6253\u52fe\u6548\u679c\u3002\u5e0c\u671b\u8fd9\u80fd\u89e3\u51b3\u60a8\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fElementUI el-table \u5b50\u8282\u70b9\u9009\u4e2d\u540e\u4e3a\u4ec0\u4e48\u6ca1\u6709\u6253\u52fe\uff1f\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>elementui el-table\u5b50\u8282\u70b9\u9009\u4e2d\u540e\u6ca1\u6709\u6253\u52fe\uff1f \u5f53\u60a8\u5728elementui\u7684el-table\u4e2d\u9009\u62e9\u5b50\u8282\u70b9\u65f6\uff0c\u4f46\u6ca1\u6709\u51fa\u73b0\u6253\u52fe\u6548\u679c\uff0c\u53ef\u80fd\u662f\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a \u5728 element-ui \u7248\u672c 2.15.7 \u4e2d\u5b58\u5728\u8fd9\u4e2a\u95ee\u9898\uff0c\u5347\u7ea7\u5230\u6700\u65b0\u7248\u672c 2.15.13 \u5373\u53ef\u89e3\u51b3\u3002 \u9664\u6b64\u4e4b\u5916\uff0c\u8bf7\u786e\u4fdd\u60a8\u9075\u5faa\u4e86\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u5728\u8868\u683c\u4e2d\u6307\u5b9a selection-change \u4e8b\u4ef6\uff0c\u4ee5\u54cd\u5e94\u5b50\u8282\u70b9\u9009\u4e2d\u3002 \u5728\u4e8b\u4ef6\u5904\u7406\u5668\u4e2d\uff0c\u4f7f\u7528 $refs.table.togglerowselection(row, true) \u65b9\u6cd5\u624b\u52a8\u52fe\u9009\u5b50\u8282\u70b9\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a &lt;el-table :data=&#8221;customlist&#8221; @selection-change=&#8221;handleselectionchange&#8221;&gt; &lt;el-table-column type=&#8221;selection&#8221; width=&#8221;55&#8243; align=&#8221;center&#8221;&gt;&lt;\/el-table-column&gt; &lt;\/el-table&gt; handleselectionchange(selection) { selection.foreach((row) =&gt; { this.$refs.table.togglerowselection(row, true); if (row.children &amp;&amp; row.children.length) { row.children.foreach((childrow) =&gt; { this.$refs.table.togglerowselection(childrow, true); }); } }); } \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f tree-props\uff0c\u8bf7\u786e\u4fdd\u4e3a children \u6307\u5b9a\u4e00\u4e2a\u552f\u4e00\u7684\u5c5e\u6027\uff0c\u5426\u5219\u65e0\u6cd5\u6b63\u786e\u9009\u62e9\u548c\u52fe\u9009\u5b50\u8282\u70b9\u3002 &lt;el-table :data=&#8221;customList&#8221; [&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-25369","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25369","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=25369"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25369\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}