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 1/2] =?UTF-8?q?BI-60932=20refactor:=20=E6=8B=93=E5=B1=95BI?= =?UTF-8?q?.concat=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 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); } }, From fcf12058c9a22dd1beec725120c48824dffe94e2 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 28 Feb 2020 16:57:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=BA=E6=95=B0?= =?UTF-8?q?=E7=BB=84=EF=BC=8C=E8=B0=83=E7=94=A8lodash=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/base.js b/src/core/base.js index b6179928f1..9138a4a5c0 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -230,7 +230,7 @@ if (!_global.BI) { }).join(""); } if (BI.isArray(obj1)) { - return [].concat.apply([], arguments); + return _.concat.apply([], arguments); } if (BI.isObject(obj1)) { return _.extend.apply({}, arguments);