【发布时间】:2016-10-16 00:06:26
【问题描述】:
我正在使用 node.js,作为一个辅助项目,我正在创建一个读取 .json 文件的模块,对其进行解析,然后根据 object properties 和 object values 创建目录结构。
对象属性(keys) 将是其自身/文件的路径,对象值将是该路径的文件列表
我试图通过对象向下递归,但我不知道如何从每个对象的最内层对象中提取路径
对象也是dynamic,由用户创建。
var path = 'c:/templates/<angular-app>';
var template = {
//outline of 'angular-app'
src:{
jade:['main.jade'],
scripts:{
modules:{
render:['index.js'],
winodws:['index.js'],
header:['header.js' ,'controller.js'],
SCSS:['index.scss' ,'setup.scss'],
}
}
},
compiled:['angular.js','angular-material.js' ,'fallback.js'],
built:{
frontEnd:[],//if the array is empty then create the path anyways
backEnd:[],
assets:{
fontAwesome:['font-awesome.css'],
img:[],
svg:[]
}
}
}
//desired result...
let out = [
'c:/template name/src/jade/main.jade',
'c:/template name/src/scripts/index.js',
'c:/template name/src/scripts/modules/render/index.js',
'c:/template name/compiled/angular.js',
'c:/template name/compiled/angular-material.js',
'c:/template name/compiled/fallback.js',
'c:/template name/built/frontEnd/',
'c:/template name/built/backEnd/',
//...ect...
];
【问题讨论】:
标签: javascript arrays node.js object recursion