gpt4 book ai didi

javascript - react native : How to format object value properly

转载 作者:行者123 更新时间:2023-12-02 23:28:34 25 4
gpt4 key购买 nike

我正在尝试创建一个空的对象。首先,每个字段都有一个带有空值的名称。一切正常,但我在格式化 name 字段

时遇到了麻烦

这是我的代码:

@observable member = {
//This name field doesn't work
[{name:''}] :
{
age: '',
email: '',
job:'',
info: [
{
email: '',
phone:'',
address: ''
}
],
}
}

当我 console.log(member) 我得到这个:

[object Object]: {dots: "", selected: "", day: "", task: Array(1), name: ""}

我想获取name:''而不是[object Object]可以这样做吗?

最佳答案

对象被写为名称:对,您的对象没有正确的键,即[{name: ''}].您可以执行以下操作来正确设置对象的格式。

@observable member = {
// will store names in array
// or just do
// name: '',
name: '',
age: '',
email: '',
job:'',
info: [
{
email: '',
phone:'',
address: ''
}
],
}

@observable member = {
names : [{'name': ''}],
memberInfo: {
age: '',
email: '',
job:'',
info: [
{
email: '',
phone:'',
address: ''
}
],
}
}

然后访问该值,例如

// if it's the array
member.names[0].name
// or if it's not an array
member.name

关于javascript - react native : How to format object value properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com