我是web开发的新手,我使用的是React,我真的不明白这个错误:我有一个对象“候选”,嵌套在一个对象"github“中,我想显示repos的数量。因此,我尝试了console.log(candidate.github.repos),但是它给我带来了一个错误:"TypeError:无法读取未定义的属性'repos‘“。但是console.log(candidate.github)正在工作并向我展示我的目标!这就是我在控制台里得到的:
Github {stars: 0, watchers: 0, forks: 0, issues: 0, size: 0, …}
stars: 0
watchers: 0
forks: 0
issues: 0
size: 0
network: 0
repos: 5
subscribers: 0
_id: "5e859c9876036d0cf33ab457"
candidate: "5df21c4417622d00137f5702"
date: "2020-04-04T10:53:19.894Z"
__proto__: Object这是我从db获取数据之后发送的候选对象:
const github = await GitHub.findOne({candidate: cand._id.toString()});
const candidateRes = {
concrete_experience: cand.concrete_experience,
chronological_experience: Array.from(cand.chronological_experience),
github
};
res.json(candidateRes);和console.log(typeof(candidate.github))发送回“Object”.
如果这是个愚蠢的错误我很抱歉但我在这里迷路了..。我做错什么了?
非常感谢你的帮助。
发布于 2020-04-06 09:02:47
我明白我愚蠢的错误。我忘了把github对象放在还原器中候选对象的initialState中,所以在提取有时间给我数据之前它是空的.但是谢谢你对我的回应伙计们!
https://stackoverflow.com/questions/61043419
复制相似问题