【问题标题】:Manipulating an array with map function in a reducer在 reducer 中使用 map 函数操作数组
【发布时间】:2017-01-09 11:16:25
【问题描述】:

我已经实施了一个操作来增加我的 svg

中我的 path d 的每个值>

在组件中

<button onClick={this.props.increase.bind(null, i)}>Increase</button>

动作

export function increase(index) {
  return {
    type: 'INCREMENT_COORDINATES',
    index
  }
}

减速器

case 'INCREMENT_COORDINATES' :
  console.log("incrementing coornidates")
  const a = action.index;
  debugger
  return state[a].d.map(x => {
    return x * 2;
  })

我得到了错误

未捕获的 TypeError:state[a].d.map 不是函数

看截图

我做错了什么,我该如何解决?,我在我的操作中返回了我的路径 d 的数组,但是我无法映射这些值

【问题讨论】:

    标签: javascript reactjs svg ecmascript-6 redux


    【解决方案1】:

    state[a].d 是一个字符串。字符串的原型中没有 map 函数。如果您需要使用字符串表示解析路径坐标,请查看此线程 - Extract x,y coordinates from arbitrary SVG path with javascript

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2014-01-29
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 2021-12-02
      相关资源
      最近更新 更多