当前位置: 首页 > news >正文

科技流小说咸阳seo公司

科技流小说,咸阳seo公司,宁波网站seo公司,织梦网站首页目录在哪里目录 功能介绍 示例 代码 视图部分 逻辑部分 完整代码 功能介绍 本文介绍了如何在Vue.js框架下实现一个树状表格#xff0c;其中支持选择子节点行的上下移动。通过这个功能#xff0c;用户可以方便地改变子节点的顺序。代码示例和详细的实现步骤将展示如何使用Vue.js的相…目录 功能介绍 示例 代码 视图部分 逻辑部分 完整代码 功能介绍 本文介绍了如何在Vue.js框架下实现一个树状表格其中支持选择子节点行的上下移动。通过这个功能用户可以方便地改变子节点的顺序。代码示例和详细的实现步骤将展示如何使用Vue.js的相关特性和组件实现这个功能。通过本文的介绍您可以轻松了解如何在您的Vue.js项目中应用这个功能以满足您的特定需求。      示例 代码 视图部分 实现父节点选择的代码 在上次选中父节点的代码基础上加上操作行生成上下移动的按钮  el-table-column aligncentertemplate slot-scopescope v-if!scope.row.childrenel-button v-show!validateOperate(scope.row, up) sizemini iconel-icon-top plainclickhandleSort(scope.row, up)/el-buttonel-button v-show!validateOperate(scope.row, down) sizemini iconel-icon-bottom plainclickhandleSort(scope.row, down)/el-button/template/el-table-column新增列定义用于显示上移和下移按钮。template 标签中定义了使用 slot-scope 来访问作用域插槽在这个作用域下使用了两个 el-button 元素来展示上移和下移按钮。为了使第一行与最后一行只有下移或上移这里通过绑定 v-show 来控制按钮的显示与隐藏根据 validateOperate() 方法的返回值确定按钮是否可见。click 侦听器则会触发 handleSort() 方法来完成所在行的移动。 逻辑部分 组件数据和选中父节点的代码相同获取tableData后如果没有index则自己遍历加上该属性。 methods对象新增方法 getParent(id) 方法用于获取拥有指定子行 id 的父级行它通过遍历 this.tableData 数组来寻找子行所属的父行。 getParent(id) {let result [];this.tableData.some(item {item.children.some(d {if (d.id id) result item;})});return result;} validateOperate(row, type) 方法用于根据指定的操作类型上移或下移检查当前行是否可进行该操作。首先判断是否最内层的子树对于上移操作当前行的索引为0时返回true隐藏上移按钮对于下移操作当前行的索引等于自身所处children数组的长度减1时返回true隐藏下移按钮。 validateOperate(row, type) {if (!row.children) {if (type up row.index 0) {return true;}else if (type down) {return this.getParent(row.id).children.length - 1 row.index;}else {return false;}}} handleSort(row, type) 方法用于处理行的上移和下移操作。它首先获取该行的父级行和父级行的 ID并定义一个标志变量 downFlag。然后通过遍历 parent.children 数组来查找需要进行上移或下移操作的行并进行相应的移动和调整索引的操作。最后更新父级行的子行列表和相关数据。 handleSort(row, type) {let parent this.getParent(row.id);let parentId;let downFlag true;this.tableData.forEach(item {if (item.children parent) parentId item.id;});console.log(parent);parent.children.some(item {if (type up) {if (item.index row.index - 1) {parent.children.splice(row.index, 1);parent.children.splice(item.index, 0, row);parent.children.forEach((child, index) child.index index);this.tableData.forEach(data {if (data.id parentId) data.children parent.children;});}} else if (type down downFlag) {if (item.index row.index 1) {parent.children.splice(row.index, 1);parent.children.splice(item.index, 0, row);parent.children.forEach((child, index) child.index index);this.tableData.forEach(data {if (data.id parentId) data.children parent.children;});downFlag false;}}})} 完整代码 templatedivel-table v-loadingloading :datatableData stylewidth: 100%;margin: 20px; row-keyid borderdefault-expand-all :tree-props{ children: children }el-table-column width60 aligncentertemplate slotheader slot-scopescopeel-checkbox :indeterminateisIndeterminate v-modelisFullChecked changecheckAllChange/el-checkbox/templatetemplate slot-scope{row} v-ifrow.childrenel-checkbox :indeterminaterow.isIndeterminate :valuerow.checked changecheckRowChange(row)/el-checkbox/template/el-table-columnel-table-column propseries label系列 aligncenter/el-table-columnel-table-column propnum label编号 aligncenter/el-table-columnel-table-column propname label名字 aligncenter/el-table-columnel-table-column aligncentertemplate slot-scopescope v-if!scope.row.childrenel-button v-show!validateOperate(scope.row, up) sizemini iconel-icon-top plainclickhandleSort(scope.row, up)/el-buttonel-button v-show!validateOperate(scope.row, down) sizemini iconel-icon-bottom plainclickhandleSort(scope.row, down)/el-button/template/el-table-column/el-table/div /templatescript export default {data() {return {isFullChecked: false,isIndeterminate: false,loading: true,tableData: []}},mounted() {this.getList()},watch: {tableData() {this.isFullChecked false;this.isIndeterminate false;}},methods: {getList() {const tableData [{id: 1,series: DDLC,children: [{id: 11,num: 1,name: monika,index: 0,},{id: 12,num: 2,name: nasuki,index: 1,},{id: 13,num: 3,name: sayori,index: 2,},{id: 14,num: 4,name: yuri,index: 3,}]},{id: 2,series: Bloom Into You,children: [{id: 21,num: 11,name: nanami,index: 0,},{id: 22,num: 12,name: yuu,index: 1,}]},];tableData.forEach(item {item.checked false;item.isIndeterminate false;})this.tableData tableData;this.total this.tableData.length;this.loading false;},checkAllChange() {const recursionSetChecked (item, checked) {item.checked checked;item.isIndeterminate false;}this.isIndeterminate false;this.tableData.forEach(item recursionSetChecked(item, this.isFullChecked));},checkRowChange(data) {data.checked !data.checked;const recursion node {if (node.children node.children.length 0)node.isIndeterminate false;return node;};this.tableData.forEach(item recursion(item));if (this.tableData.every(item item.checked)) {this.isFullChecked true;}else if (this.tableData.every(item !item.checked)) {this.isFullChecked false;}this.isIndeterminate this.tableData.some(item item.isIndeterminate)? true: this.tableData.some(item !item.checked) this.tableData.some(item item.checked);},getParent(id) {let result [];this.tableData.some(item {item.children.some(d {if (d.id id) result item;})});return result;},validateOperate(row, type) {if (!row.children) {if (type up row.index 0) {return true;}else if (type down) {return this.getParent(row.id).children.length - 1 row.index;}else {return false;}}},handleSort(row, type) {let parent this.getParent(row.id);let parentId;let downFlag true;this.tableData.forEach(item {if (item.children parent) parentId item.id;});console.log(parent);parent.children.some(item {if (type up) {if (item.index row.index - 1) {parent.children.splice(row.index, 1);parent.children.splice(item.index, 0, row);parent.children.forEach((child, index) child.index index);this.tableData.forEach(data {if (data.id parentId) data.children parent.children;});}} else if (type down downFlag) {if (item.index row.index 1) {parent.children.splice(row.index, 1);parent.children.splice(item.index, 0, row);parent.children.forEach((child, index) child.index index);this.tableData.forEach(data {if (data.id parentId) data.children parent.children;});downFlag false;}}})}} } /script
http://www.zqtcl.cn/news/113460/

相关文章:

  • 过年做那个网站致富盘锦网站建设vhkeji
  • 网站semseo先做哪个关键词投放
  • 药品招商网站大全南阳做网站公司电话
  • 优秀手机网站大学生创新产品设计作品
  • 备案期间关闭网站宝应人才网
  • 响应式网站一般做几个版本官网+wordpress
  • 太原网站建设方案服务佛山市建设工程有限公司
  • 智能网站建设平台php mysql 网站源码
  • 夏天做那些网站能致富百度关键词价格怎么查询
  • 厦门微信网站专业从事网站开发公司
  • 网站标题的写法湖南如何做网络营销
  • 设计做兼职的网站求推荐医院英文网站建设
  • 有没得办法可以查询一个网站有没得做竞价呀ai可以用来做网站吗
  • 俄乌局势最新消息惠州seo排名优化
  • 常州发布信息的有什么网站电商平台建设公司
  • 高新区手机网站建设长沙关键词优化服务
  • 网站开发预算报价表推销网站的方法
  • 做网站需要几个人昆明旅行社网站开发
  • 上海产品网站建设网站建设分为哪些
  • 史志网站建设在线网站建设工程标准
  • 青海省建设工程在哪个网站发布北京专业网站外包公司
  • 东营网站建设公司wordpress获取子分类
  • 网站的尾页要怎么做d代码做网站
  • 自己做一元购网站烟台网站设计公司推荐
  • 有没有做彩票直播的网站成都十八个网红打卡地
  • 急求聊城网站建设网站服务器管理系统
  • 做网站需要什么许可证商场设计效果图
  • html网页制作视频windows优化大师有哪些功能
  • 国外建站主机帝国手机网站cms系统
  • 响应式网站建设哪家好网站空间支付方式