|
|
@ -89,30 +89,34 @@ Array.prototype.forAsync = function (callBack, finish) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 数组递归循环
|
|
|
|
* 数组递归循环
|
|
|
|
* callBack(item,depth) 处理函数接受两个参数
|
|
|
|
* callBack(item,depth) 必选 处理函数
|
|
|
|
* item 循环对象
|
|
|
|
* children 可选 默认子类属性[children]
|
|
|
|
* depth 循环深度数组[0,0,0]长度即为深度
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
Array.prototype.forTreeDepth = function (callBack) {
|
|
|
|
Array.prototype.forTreeDepth = function (callBack, children) {
|
|
|
|
(function loop(data, depth) {
|
|
|
|
(function loop(data, depth) {
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
|
|
data.forEach(function (item, i) {
|
|
|
|
data.forEach(function (item, i) {
|
|
|
|
var depth_ = depth.slice(0);
|
|
|
|
var depth_ = depth.slice(0);
|
|
|
|
depth_.push(i);
|
|
|
|
depth_.push(i);
|
|
|
|
callBack(item, depth_);
|
|
|
|
callBack(item, depth_);
|
|
|
|
loop(item.children, depth_);
|
|
|
|
if (typeof(children) == "undefined") {
|
|
|
|
|
|
|
|
loop(item.children, depth_);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
loop(item[children], depth_);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})(this, []);
|
|
|
|
})(this, []);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 数组递归循环
|
|
|
|
* 数组递归循环
|
|
|
|
* callBack(item) 处理函数
|
|
|
|
* callBack(item) 必选 处理函数
|
|
|
|
|
|
|
|
* children 可选 默认子类属性[children]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
Array.prototype.forTree = function (callBack) {
|
|
|
|
Array.prototype.forTree = function (callBack, children) {
|
|
|
|
this.forTreeDepth(function (item, depth) {
|
|
|
|
this.forTreeDepth(function (item, depth) {
|
|
|
|
callBack(item);
|
|
|
|
callBack(item);
|
|
|
|
})
|
|
|
|
}, children)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 自定义Map对象
|
|
|
|
* 自定义Map对象
|
|
|
|