`

文件夹转换成ztree树形二维数组的脚本

 
阅读更多

上一次下载了rexsee的代码(后来发现code.google.com上有,名字叫jinghongye),但没有导航,就用ztree做个树形菜单,树形json用代码生成了下——使用groovy,动态语言,你懂的

 

import com.alibaba.fastjson.JSON


File f = new File('src/java')
def filePathLl = []
f.eachFileRecurse{
	filePathLl << it.absolutePath
}

// 根据父文件夹获取其下标作为pId
def ll = []
f.eachFileRecurse{one ->
	int pId = filePathLl.indexOf(one.parentFile.absolutePath) + 1
	int id = filePathLl.indexOf(one.absolutePath) + 1

	if(one.name ==~ /.+[xml|java]$/ || one.isDirectory()){
		if(one.isFile()){
			String linkPath = one.absolutePath.replace(f.absolutePath, '')
			linkPath = linkPath.replaceAll("\\\\", '/').substring(1)
			ll << [id: id, name: one.name, pId: pId, linkPath: linkPath]
		}else{
			ll << [id: id, name: one.name, pId: pId]
		}
	}
}

// 生成ztree使用的json数据
new File('output/jsonData.js').text = 'var zNodes = ' + JSON.toJSONString(ll)

 

BTW: 吐槽下rexsee——官网下载的模拟器apk反编译后的jar,源码和官方公布的源码不同,不及时更新,这个对开发者太不糊弄了吧??还有就是一堆字符串+操作,看jar源码,优化了很多StringBuilder对象,为什么不用一个android兼容的模板引擎??或者为了性能用StringBuffer也可以啊

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics