From 683f966515b9477cc71086bf4b82351aade70309 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 15 May 2017 18:58:44 +0800 Subject: [PATCH] Tree --- bi/core.js | 13 ++++++ bi/polyfill.js | 93 ++++++++++++++++++++++++++++++++++++++++++ docs/core.js | 13 ++++++ docs/polyfill.js | 93 ++++++++++++++++++++++++++++++++++++++++++ src/core/utils/tree.js | 13 ++++++ 5 files changed, 225 insertions(+) create mode 100644 bi/polyfill.js create mode 100644 docs/polyfill.js diff --git a/bi/core.js b/bi/core.js index af4d547e4..7d6a75020 100644 --- a/bi/core.js +++ b/bi/core.js @@ -10403,6 +10403,19 @@ $.extend(BI, { } else { return [sNodes]; } + }, + + traversal: function (array, callback) { + if (BI.isNull(array)) { + return; + } + var self = this; + BI.any(array, function (i, item) { + if (callback(i, item) === false) { + return true; + } + self.traversal(item.children, callback); + }) } }) })();//向量操作 diff --git a/bi/polyfill.js b/bi/polyfill.js new file mode 100644 index 000000000..854ed288f --- /dev/null +++ b/bi/polyfill.js @@ -0,0 +1,93 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +}/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +});//修复ie9下sort方法的bug +!function (window) { + var ua = window.navigator.userAgent.toLowerCase(), + reg = /msie|applewebkit.+safari/; + if (reg.test(ua)) { + var _sort = Array.prototype.sort; + Array.prototype.sort = function (fn) { + if (!!fn && typeof fn === 'function') { + if (this.length < 2) { + return this; + } + var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; + for (; i < l; i++) { + for (j = i + 1; j < l; j++) { + t = fn.call(this, this[i], this[j]); + r = (typeof t === 'number' ? t : + !!t ? 1 : 0) > 0; + if (r === true) { + tmp = this[i]; + this[i] = this[j]; + this[j] = tmp; + } + } + } + return this; + } else { + return _sort.call(this); + } + }; + } +}(window); \ No newline at end of file diff --git a/docs/core.js b/docs/core.js index e1ec3a400..14ffbdf52 100644 --- a/docs/core.js +++ b/docs/core.js @@ -18862,6 +18862,19 @@ $.extend(BI, { } else { return [sNodes]; } + }, + + traversal: function (array, callback) { + if (BI.isNull(array)) { + return; + } + var self = this; + BI.any(array, function (i, item) { + if (callback(i, item) === false) { + return true; + } + self.traversal(item.children, callback); + }) } }) })();//向量操作 diff --git a/docs/polyfill.js b/docs/polyfill.js new file mode 100644 index 000000000..854ed288f --- /dev/null +++ b/docs/polyfill.js @@ -0,0 +1,93 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +}/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +});//修复ie9下sort方法的bug +!function (window) { + var ua = window.navigator.userAgent.toLowerCase(), + reg = /msie|applewebkit.+safari/; + if (reg.test(ua)) { + var _sort = Array.prototype.sort; + Array.prototype.sort = function (fn) { + if (!!fn && typeof fn === 'function') { + if (this.length < 2) { + return this; + } + var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; + for (; i < l; i++) { + for (j = i + 1; j < l; j++) { + t = fn.call(this, this[i], this[j]); + r = (typeof t === 'number' ? t : + !!t ? 1 : 0) > 0; + if (r === true) { + tmp = this[i]; + this[i] = this[j]; + this[j] = tmp; + } + } + } + return this; + } else { + return _sort.call(this); + } + }; + } +}(window); \ No newline at end of file diff --git a/src/core/utils/tree.js b/src/core/utils/tree.js index 51ac0f23b..139dedce1 100644 --- a/src/core/utils/tree.js +++ b/src/core/utils/tree.js @@ -464,6 +464,19 @@ } else { return [sNodes]; } + }, + + traversal: function (array, callback) { + if (BI.isNull(array)) { + return; + } + var self = this; + BI.any(array, function (i, item) { + if (callback(i, item) === false) { + return true; + } + self.traversal(item.children, callback); + }) } }) })(); \ No newline at end of file