简体   繁体   English

获得未定义是不可迭代的(无法读取属性 Symbol(Symbol.iterator))

[英]getting undefined is not iterable (cannot read property Symbol(Symbol.iterator))

Learning React by coding, here i got this error (Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) ), dont know where is the problem, any suggestion?通过编码学习 React,在这里我得到了这个错误(Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))),不知道问题出在哪里,有什么建议吗?

simply useEffect activates setFilteredData which gives: `只需 useEffect 激活 setFilteredData 即可:`

{
links: [
  {
    color: 'red'
  },
],
nodes: [
  {
    focused: focused
  },
],
};

`

i want to take that data and change it a little, like my logic is, color should be grey or red if id's matches and also focus should be focus if id's matches, english is not my mother language so could be mistakes.我想获取该数据并对其进行一些更改,就像我的逻辑一样,如果 id 匹配,颜色应该是灰色或红色,如果 id 匹配,则焦点应该是焦点,英语不是我的母语,所以可能是错误的。 any ideas?有任何想法吗? i hope my question is clear, if needs to add something or not clear, just tell me.我希望我的问题很清楚,如果需要添加或不清楚,请告诉我。

 const [filteredData, setFilteredData] = useState(); const LINK_COLOR = "grey"; const LINK_FOCUS_COLOR = "red"; useEffect(() => { const filterData = () => { setFilteredData({ links: links, nodes: allNodes }); }; filterData(); }, [...]); const focusLinkId = currentLink? currentLink.id: ""; const focusNodeId = currentNode? currentNode.id: ""; const graphData = {...filteredData, links: [...filteredData?.links, { color: filteredData?.links?.map((l) => { const color = l?.id === focusLinkId? LINK_FOCUS_COLOR: LINK_COLOR; return color; }), }, ], nodes: [...filteredData?.nodes, { focused: filteredData?.nodes?.map((n) => { const focused = n?.id === focusNodeId; return focused; }), }, ], }; console.log("graphData:", graphData); <Graph id="graph-id" data={graphData? graphData: visualGraph.model} />

As said in the comments, filteredData is undefined until the response comes back正如评论中所说, filteredData在响应返回之前是undefined

This should help:这应该有助于:

const graphData = filteredData && { /* ... */ }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 × TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) - × TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) - TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator)) 我收到错误“未捕获的 TypeError:未定义不可迭代(无法读取属性 Symbol(Symbol.iterator))”。 无法找到解决方案 - I am getting an error "Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))". Unable to find solution Firebase 函数问题:(未定义)对象不可迭代(无法读取属性 Symbol(Symbol.iterator)) - Firebase Functions trouble: (undefined) object is not iterable (cannot read property Symbol(Symbol.iterator)) Storybook 抛出错误:未定义不可迭代(无法读取属性 Symbol(Symbol.iterator)) - Storybook throws error: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 不知道该怎么做 - Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) Not sure what to do Reactjs函数不能正确返回多个值:TypeError:undefined不可迭代(无法读取属性Symbol(Symbol.iterator)) - Reactjs function not returning multiple values properly: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 无法读取未定义的属性 &#39;Symbol(Symbol.iterator)&#39; - Cannot read property 'Symbol(Symbol.iterator)' of undefined 节点红色无法读取未定义的属性&#39;Symbol(Symbol.iterator)&#39; - Node red Cannot read property 'Symbol(Symbol.iterator)' of undefined EOSJS和Scatter-无法读取未定义的属性&#39;Symbol(Symbol.iterator)&#39; - EOSJS & Scatter - Cannot read property 'Symbol(Symbol.iterator)' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM