From 942777b507f8aee2a8abbda6df7315f06fc0f719 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 28 Feb 2020 16:06:07 +0800 Subject: [PATCH] =?UTF-8?q?BI-60932=20refactor:=20=E6=8B=93=E5=B1=95BI.con?= =?UTF-8?q?cat=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E4=B8=8D=E5=AE=9A=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + src/core/__test__/base.test.js | 22 ++++++++++++++++++++++ src/core/base.js | 8 +++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index c4c3d67d5..ace18e4cb 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 5184f79bf..1b3ab1ebd 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 6d326cea1..b6179928f 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); } },