1
我想爲我的反應組件自動生成樹視圖。我有自己的路徑多個文件。對於exmple:Lodash自動生成樹視圖
- COM /公司/模型/ Main.java
- COM /公司/控制器/ Move.java
- COM /公司/控制器/ Rotate.java
- COM /公司/視圖/Watch.java
的目標是有一個對象的數據看起來像這樣:
var data = {
name: com,
children: [{name: company,
children: [
{name: model,
children: [{name: Main.java}]
},
{name: controller,
children: [{name: Move.java},{name: Rotate.java}]
},
{name: view,
children: [{name: Watch.java}]
}
]}]
}
我發現這個lib添加到我的道路被劃分爲標籤:https://nodejs.org/api/path.html
像這樣:
var path = com/company/model/Main.java ;
var dirname = path.dirname(path); // => « com/company/model »
var folders = dirname.split(path.sep); // => folders = [‘com’,’compagny’,’model’]
我試圖用lodash https://lodash.com/docs 爲了不更迭自動生成這個你能幫助我,請
非常感謝:) – fandro