zarm
Version:
基于 React 的移动端UI库
28 lines (24 loc) • 673 B
JavaScript
function parseDataSource(months, locale) {
var dataSource = {};
for (var i = 0; i < months.length; i++) {
var year = months[i].getFullYear();
var month = months[i].getMonth();
if (!dataSource[year]) {
dataSource[year] = {
value: year,
label: year,
children: [{
value: month,
label: locale === null || locale === void 0 ? void 0 : locale.months[month]
}]
};
} else {
dataSource[year].children.push({
value: month,
label: locale === null || locale === void 0 ? void 0 : locale.months[month]
});
}
}
return dataSource;
}
export default parseDataSource;