FileNavigator.prototype.buildTree = function(path) {
var self = this;
var recursive = function(parent, file, path) {
var absName = path ? (path + '/' + file.name) : file.name;
if (parent.name && !path.match(new RegExp('^' + parent.name))) {
parent.nodes = [];
}
if (parent.name !== path) {
for (var i in parent.nodes) {
recursive(parent.nodes[i], file, path);
}
} else {
for (var i in parent.nodes) {
if (parent.nodes[i].name === absName) {
return;
}
}
parent.nodes.push({name: absName, nodes: []});
}
};
!self.history.length && self.history.push({name: path, nodes: []});
for (var i in self.fileList) {
var file = self.fileList[i].model;
file.type === 'dir' && recursive(self.history[0], file, path);
}
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句