Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

树形表格无法通过指定父级id以及子级id渲染表格,必须在返回的数据结构中指定children才可以加载树形表格 #1885

Closed
4 tasks done
XieYun51 opened this issue May 10, 2024 · 9 comments · Fixed by #1913
Labels
docs 文档或示例

Comments

@XieYun51
Copy link

议题条件

  • 我确认已查看官方使用文档:https://layui.dev ,但没有找到相关解决方案。
  • 我确认已在 Issues 中搜索过类似的问题,但没有找到相关解决方案。
  • 我已仔细阅读: 🍀 Layui Issue 贡献指南

议题类型

疑是 BUG

使用版本

2.9.9

问题描述

无法通过指定父级id以及子级id来渲染树形表格,必须在返回的数据结构中组装好对应的数据结构比如要指定children,特别麻烦,还得在后端重新计算再组装数据结构然后再返回前端,我记得之前是可以直接在前端中指定父级id以及子级id,layui会根据父子id自动渲染他们的层级关系

业务代码

var inst = treeTable.render({

            elem: "#menu-treeTable",
            url: "/users/menuLists",
            request: {
                pageName: 'curPage',
                limitName: 'pageSize'
            },
            page: true,
            toolbar: '#menu-treeTable-method',
            done: function(res, curr, count, origin) {
            },

            tree: { // treeTable 特定属性集

                customName: {
                    name: 'menuName',
                    id: 'menuId',
                    pid: 'menuParentId'
                },



            },
            cols: [
                [{type: 'checkbox', fixed: 'left'},

                {field: 'id', title: '编号', width: 80, align: "center"},

                {field: 'menuName', title: '菜单名称', align: "center"},

                {field: 'menuUrl', title: '菜单地址', align: "center"},

                {field: 'menuIcon', title: '菜单图标',align: "center", width: 150,templet:iconTpl},

                {field: 'menuType', title: '菜单类型',align: "center",templet:typeTpl},
                {field: 'menuShow', title: '可见',align: "center",templet:showTpl},
                {fixed: "right", title: "操作",width: 260, align: "center",toolbar: "#menu-treeTable-utils"}

            ]]

        });

截图补充

0809a8beca5482f6ff009d3c95f6286
Uploading 7e92fd2ff4f38d058a38231e565790e.png…

浏览器

Chrome83.0.4103.106

演示地址

No response

友好承诺

  • 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护 Layui 良好的社区氛围。
@LSL1618
Copy link
Collaborator

LSL1618 commented May 10, 2024

treeTable树表的customName属性不是已经支持你的要求嘛。

@XieYun51
Copy link
Author

但是在渲染树形表格的时候层级嵌套没有显现出来,而且也没有缩进,只是按照顺序把数据库中的数据渲染到表格了。
ed8e8143c12985a81f32e63a4342aba

@hjingsuper
Copy link
Contributor

hjingsuper commented May 10, 2024

提问时还是先到社区检索下,这个问题已经有回答了 ref:#1736

@XieYun51
Copy link
Author

看了你发的链接地址,没有说明啥问题啊

@XieYun51
Copy link
Author

已解决,需要使用简单数据模式才可以,文档写的很模糊

@LSL1618
Copy link
Collaborator

LSL1618 commented May 10, 2024

已解决,需要使用简单数据模式才可以,文档写的很模糊

isSimpleData这个属性的说明确实解释得比较模糊,应该解释为是否平级数据结构或者层级数据结构,这样会更好理解。

@hjingsuper
Copy link
Contributor

不好意思,理解错了。当时我做的时候以为isSimpleData只是treeTable.getData(id, isSimpleData);有用
使用简单数据结构直接指定父子属性确实可自动渲染层级关系

@XieYun51
Copy link
Author

相互学习,刚开始有很多不懂的地方,慢慢积累 @hjingsuper

@Sight-wcg Sight-wcg added the docs 文档或示例 label May 11, 2024
@Sight-wcg
Copy link
Collaborator

关闭,因为这不是 BUG

@Sight-wcg Sight-wcg closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs 文档或示例
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants