Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let array = [
- {trid: 1, trname: "餐厅服务员", parent_id: 0, path: ",1,"},
- {trid: 2, trname: "公共营养师", parent_id: 0, path: ",2,"},
- {trid: 315, trname: "初级", parent_id: 314, path: "314,315,"},
- {trid: 5, trname: "初级", parent_id: 1, path: ",1,5,"}
- ];
- // 设置要处理的属性名称
- const pathLens = R.lensProp('path');
- // 判断参数是否非空
- const notEmpty = R.compose(R.not, R.isEmpty);
- // 获取对象中指定属性,并分割成数组
- const getPath = obj => R.view(pathLens)(obj).split(',');
- // 只保留分割后数组的非空元素
- const unEmptyPath = R.compose(R.filter(notEmpty), getPath);
- // 将处理后的属性值保存至原对象中
- const normalizePath = (obj) => {
- return R.set(pathLens)((unEmptyPath)(obj))(obj);
- }
- // 批处理对象数组
- R.map(normalizePath, array);
Add Comment
Please, Sign In to add comment