Element升级

Former-commit-id: 1dd17d813af5b1be5ab08d0452d73c2f68dae331
master
wangbingit@outlook.com 4 years ago
parent eb5f70683a
commit a97556d26e

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

Loading…
Cancel
Save

Powered by TurnKey Linux.