Guest User

Untitled

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