Iva*_*her 4 javascript angularjs angularjs-directive
我不确定如何以有棱角的方式做这件事.
它应该实现的功能是:
所以我现在所拥有的是一个文件和文件夹列表作为路径数组.这是由onDrop或onChange事件(来自拖放或输入)生成的.
关于如何实现这一点的任何建议?
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);
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23410 次 |
| 最近记录: |