Browse Source

BI-60932 refactor: 拓展BI.concat使其可以传入不定参数

es6
windy 5 years ago
parent
commit
942777b507
  1. 1
      changelog.md
  2. 22
      src/core/__test__/base.test.js
  3. 8
      src/core/base.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志
2.0(2020-2)
- 拓展BI.concat,使其可以拼接多个数组
- 修复勾选节点不影响父子节点勾选状态的树搜索选中getValue不正常的问题
2.0(2020-1)

22
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
});
});
});

8
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);
}
},

Loading…
Cancel
Save