我有一个用户数组,我知道它有11个值,因为当我打印到控制台时它将显示所有数组元素。但是,当我使用-
users.map(printLog)
function printLog(item,index){console.log(item.text);}`
它返回11个未定义的值,有什么建议吗?
我正在用react编写它,而我正在使用的实际代码段是return <div>{users.map(user=> (<div key={user.id}>{user.text};</div>))}</div>;
更新:这是打印用户时返回的数组。 (对不起,我最初没有包括在内)
{id: "5b27fd770fdd1f04b257dfc2", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b27fd770fdd1f04b257dfc2"}
{id: "5b27fd7a0fdd1f04b257dfc3", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b27fd7a0fdd1f04b257dfc3"}
{id: "5b28070eb9c7600551e5a1c0", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b28070eb9c7600551e5a1c0"}
{id: "5b28076eb9c7600551e5a1c1", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b28076eb9c7600551e5a1c1"}
{id: "5b2807f1b9c7600551e5a1c2", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b2807f1b9c7600551e5a1c2"}
{id: "5b28082eb9c7600551e5a1c3", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b28082eb9c7600551e5a1c3"}
{id: "5b28085cb8b563056546e737", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b28085cb8b563056546e737"}
{id: "5b28085fb8b563056546e738", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b28085fb8b563056546e738"}
{id: "5b28086ab8b563056546e739", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b28086ab8b563056546e739"}
{id: "5b280872b8b563056546e73a", name: "Kylo Ren", complete: false, __typename: "User", Symbol(id): "User:5b280872b8b563056546e73a"}
{id: "5b280da6a766dd058f73b3bf", name: "Ben", complete: false, __typename: "User", Symbol(id): "User:5b280da6a766dd058f73b3bf"}
答案 0 :(得分:1)
您的用户对象没有text
成员。尝试将user.text
替换为user.name
(这可能是您想要的,但尚不完全清楚)。