在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ iview樹形組件使用問題,已經(jīng)有后臺(tái)數(shù)據(jù),請(qǐng)問如何對(duì)應(yīng)treeData的字段?

iview樹形組件使用問題,已經(jīng)有后臺(tái)數(shù)據(jù),請(qǐng)問如何對(duì)應(yīng)treeData的字段?

children: [

        {
          title: 'child 1-1',
          expand: true,
          children: [
            {
              title: 'leaf 1-1-1',
              expand: true
            },
            {
              title: 'leaf 1-1-2',
              expand: true
            }
          ]
        },
        {
          title: 'child 1-2',
          expand: true,
          children: [
            {
              title: 'leaf 1-2-1',
              expand: true
            },
            {
              title: 'leaf 1-2-1',
              expand: true
            }
          ]
        }
      ]
      

這是iview的demo數(shù)據(jù),這里面children title是固定的字段和我們回臺(tái)返回?cái)?shù)據(jù)字段不對(duì)應(yīng)怎么辦?求指教,比如我真實(shí)數(shù)據(jù)是childrenFilenames,還有就是我不知道有多少層級(jí),怎么和demo里tree對(duì)應(yīng)呢

回答
編輯回答
來守候

不知道樓主解決了沒,我也遇到這樣的問題,求指教

2017年11月19日 02:53
編輯回答
法克魷

只能去解析一遍了唄, 下面的方法給你參考

    function getTree(tree = []) {
        let arr = [];
        if (!!tree && tree.length !== 0) {
            tree.forEach(item => {
                let obj = {};
                obj.title = item.name;
                obj.attr = item.attr; // 其他你想要添加的屬性
                obj.expand = false;
                obj.selected = false;
                obj.children = getTree(item.childrenFilenames); // 遞歸調(diào)用
                arr.push(obj);
            });
        }
        return arr;
    },
2018年3月3日 14:18
編輯回答
深記你

我是把title更換成自己的字段名稱,render,renderContent渲染數(shù)據(jù) data.字段名稱。。。不知道是不是這樣

2017年8月17日 19:45