代码示例:https://github.com/maxsky/imitate-tb-combo-select
Demo 演示:https://codepen.io/maxsky/pen/oNLWgNp
function calcDescartes (array) {
if (array.length < 2) return array[0] || [];
return [].reduce.call(array, function (col, set) {
var res = [];
col.forEach(function (c) {
set.forEach(function (s) {
var t = [].concat(Array.isArray(c) ? c : [c]);
t.push(s);
res.push(t);
})
});
return res;
});
}
console.log(calcDescartes([[1,2,3],['a','b','c']]));
在 Chrome 运行一下: