为了账号安全,请及时绑定邮箱和手机立即绑定

管道,带有动态参数的 ramda

管道,带有动态参数的 ramda

守着星空守着你 2021-06-02 07:38:33
cons columnDefs = [   {     label: 'The_First_Name',     value: getProp,     args: ['firstName'] // different number of arguments depending on function   },   {     label: 'City',     value: getNestedProperty,     args: ['location', 'city']    }]const data = [  {     firstName: 'Joe',     lastName: 'Smith',     location: {       city: 'London'     }  },   {     firstName: 'Anna',     lastName: 'Andersson',     location: {       city: 'Stockholm'     }  }]const getProp = (object, key) => R.prop(key, object);const getNestedProperty = (obj, args) => R.path(..args, obj);用于映射数据的 Ramda 管道:const tableBuilder = R.pipe(R.map); // some ramda functions in hereconst rows = tableBuilder(data, columnDefs);想要的输出:rows output:[   {      The_First_Name: 'Joe',      city: 'London'   },   {      The_First_Name: 'Anna',      city: 'Stockholm'   }]每一行的关键是label在属性columnDefs。该值Ramda与valueprop 中定义的参数一起从prop 中的函数中获取args。https://plnkr.co/edit/rOGh4zkyOEF24TLaCZ4e?p=preview完全卡住了。这甚至可能与 Ramda 有关吗?还是用普通的 javascript 来做更好?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 134 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信