A few erros with this which is best answered with some space, I think what you were trying to do was this, I have turned privilegesOption
into an array []
containing objects {}
where the object key:value pairs are seperated by a comma ,
(最好用一些空格来解决这个问题,我想您正在尝试做的是,我已经将privilegesOption
变成了一个包含对象{}
的数组[]
,其中对象的key:value对用逗号分隔,
)
this.state = {
privilegesOption: [
{
key: 1,
text: "Admin",
value: 1
},
{
key: 2,
text: "Cashier",
value: 2
}
]
}
And to find
the object where value is 1 you were completely right
(并find
值等于1的对象,那是完全正确的)
let privilagesOut = this.state.privilegesOption.find(x => x.value == 1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…