diff --git a/changelog.md b/changelog.md index c4c3d67d57..ace18e4cb8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2020-2) +- 拓展BI.concat,使其可以拼接多个数组 - 修复勾选节点不影响父子节点勾选状态的树搜索选中getValue不正常的问题 2.0(2020-1) diff --git a/src/core/__test__/base.test.js b/src/core/__test__/base.test.js index 5184f79bff..1b3ab1ebd8 100644 --- a/src/core/__test__/base.test.js +++ b/src/core/__test__/base.test.js @@ -107,4 +107,26 @@ describe("baseFunctionTest", function () { var a = BI.makeArray(2, 1); expect(a).to.deep.equal([1, 1]); }); + + + /** + * test_author_windy + */ + it("concat-string", function () { + // concat-string + expect(BI.concat("a", "b", "c")).to.equal("abc"); + + // concat-array + expect(BI.concat([1], [2], [3])).to.deep.equal([1, 2, 3]); + + // concat-object-array + expect(BI.concat([{text: 1, value: 1}], [{text: 2, value: 2}], [{text: 3, value: 3}])).to.deep.equal([{text: 1, value: 1}, {text: 2, value: 2}, {text: 3, value: 3}]); + + // concat-object + expect(BI.concat({a: 1}, {b: 2}, {c: 3})).to.deep.equal({ + a: 1, + b: 2, + c: 3 + }); + }); }); diff --git a/src/core/base.js b/src/core/base.js index 6d326cea13..b6179928f1 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -225,13 +225,15 @@ if (!_global.BI) { concat: function (obj1, obj2) { if (BI.isKey(obj1)) { - return obj1 + "" + obj2; + return BI.map([].slice.apply(arguments), function (idx, v) { + return v; + }).join(""); } if (BI.isArray(obj1)) { - return obj1.concat(obj2); + return [].concat.apply([], arguments); } if (BI.isObject(obj1)) { - return _.extend({}, obj1, obj2); + return _.extend.apply({}, arguments); } },