react 樹遞歸

  var data = [{
          name:1,
          next:[{name:4},{name:999}]
        },{name:2} , {name:3}]io

        function clickMod(){
            return function(){
              alert("hhhhhhhhh")
            }
        }console

        function styleName(){
          return {
            background:'green',
            color:'red',
            marginBottom:'50px'
          }
        }function

        function createTreeDate(data){  
              if(data){
                  let lis=[];
                  for(let index in data){
                      console.log("index:" , index)
                      let childrenDiv = null;cli

                      if(data[index].next){
                          let next= createTreeDate(data[index].next);
                          childrenDiv=<div onClick={clickMod()}>{next}</div>;
                      }next

                      let li = <li style={styleName()} key={index}>
                          <div>{data[index].name}</div>
                          {childrenDiv}
                      </li>;margin

                      lis.push(li);
                  }
                  return <ul>{lis}</ul>
              }di

          }co

          let treeHtml =createTreeDate(data);
        
        return (
          <div>
              {treeHtml}
             
          </div>
        )let

相關文章
相關標籤/搜索