Uncaught TypeError: Cannot read property 'reduce' of undefined

来源:4-7 话题详情页

慕侠3851047

2018-07-16

@computed get detailMap() { // 方便获取某个 id 下的 detail
  return this.details.reduce((result, detail) => {
    console.log("getTopic deail.id: ", detail.id) // eslint-disable-line
    result[detail.id] = detail // eslint-disable-line
    console.log("getTopic result: ", result) // eslint-disable-line
    return result
  }, {})
}


查看到的 result 是这个对象


//img.mukewang.com/szimg/5b4c97400001bf7a06970598.jpg


错误

Uncaught TypeError: Cannot read property 'reduce' of undefined
    at Object.get (topic-store.js?a13d:52)
    at ComputedValue$$1.computeValue (mobx.module.js?daf9:875)
    at ComputedValue$$1.get (mobx.module.js?daf9:805)
    at ObservableObjectAdministration$$1.read (mobx.module.js?daf9:3413)
    at Object.get (mobx.module.js?daf9:3673)
    at backend.js:7516
    at Array.forEach (<anonymous>)
    at Bridge._inspectResponse (backend.js:7512)
    at Bridge._handleMessage (backend.js:7393)
    at listener (backend.js:86)


details 内容


http://img.mukewang.com/szimg/5b4d66600001e47f08400843.jpg

写回答

1回答

Jokcy

2018-07-17

报错是reduce方法,你的detials是什么内容?

0
3
慕侠3851047
回复
Jokcy
好的,谢谢老师
2018-07-17
共3条回复

React全栈+服务器渲染(ssr)打造社区Webapp

【毕设面试】只会写业务代码?out了,带你学会搭建属于自己的工程!

768 学习 · 414 问题

查看课程