Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

reactjs - How to use getSubRows and useExpanded on a table without using subRows object property

I need to show some information in a table, the rows in the table must be expandable according to some data. I have an array like this:

const data = [
            ['0','some name','ok'],
            ['0.1','some name','ok'],
            ['0.1.01','some name', 'ok'],
            ['0.1.01.01','some name','ok'],
            ['0.1.01.02','some name','ok'],
            ['1','some name','ok'],

        ]

i need to use this dot notation string as the subRows hierarchy so it would looks like:

  code         decription  status
__________________________________
+ 0            some text   ok
  + 0.1        some text   ok
    + 0.1.01   some text   ok
    + 0.1.02   some text   ok
+ 1            some text   ok

i tried to format the data so it would looks like

const data = [{
    code: "0"
    name: "some name"
    status: "ok"
    data:[{
        code: "0.1"
        name: "some name"
        status: "ok"
        data:[
        {
            code: "0.1.01"
            name: "some name"
            status: "ok"
            data: []
        },
        {
            code: "0.1.02"
            name: "some name"
            status: "ok"
            data:[]
        }
        ]
    },
    {
    code: "1"
    name: "some name"
    status: "ok"
    data[]
    }
    
    ]
}]

but i wasn't able so i'm looking to use something like

const data = [
  {
    code: "0",
    name: "some name",
    status: "ok",
    id:"0",
    parentId:null
  },
  {
    code: "0",
    name: "some name",
    status: "ok",
    id:"0.1",
    parentId:"0"
  },
  {
    code: "0",
    name: "some name",
    status: "ok",
    id:"0.1.01",
    parentId:"0.1"
  }
]

so "id" and "parendId" properties will define collapse subRow

How can i rewrite getSubRow function to take id and parentId?

question from:https://stackoverflow.com/questions/65713968/how-to-use-getsubrows-and-useexpanded-on-a-table-without-using-subrows-object-pr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...