UNPKG

trs-ui-app

Version:

TRS 可视化低代码平台 前端移动 UI 组件库 👍

40 lines (38 loc) 1.14 kB
const groupArray = (array, subGroupLength) => { let index = 0; const newArray = []; while (index < array.length) { newArray.push(array.slice(index, (index += subGroupLength))); } return newArray; }; const groupingData = (data, filed) => { const map = {}; const dest = []; data.forEach((item) => { if (!map[item[filed]]) { dest.push({ [filed]: item[filed], list: [item], }); map[item[filed]] = item; } else { dest.forEach((dItem) => { if (dItem[filed] === item[filed]) { dItem.list.push(item); } }); } }); return dest; }; const textLengthLimit = (str, limit) => { return String(str).length > limit ? `${String(str).slice(0, limit)}...` : String(str); }; const filterHTML = (html) => { const div = document.createElement('div'); div.innerHTML = html; return div.textContent || div.innerText || ''; }; export { filterHTML, groupArray, groupingData, textLengthLimit };