【发布时间】:2020-05-19 05:13:48
【问题描述】:
我有两个数组,“电话”和“其他电话”以及一些联系方式。现在我想比较这两个数组并将“调用”数组中的“状态”属性更新为 false。状态值应仅在“Othercalls”数组中的联系人中更改。
我在这里尝试的是,
这是我的两个数组。
this.state = {
calls: [
{
fullname: 'Mark Doe',
phoneNumber: '0112234567',
status: true
},
{
fullname: 'Clark Man',
phoneNumber: '0723434567',
status: true
},
{
fullname: 'Jaden Boor',
phoneNumber: '0778902356',
status: true
},
{
fullname: 'Srick Tree',
phoneNumber: '0980234589',
status: true
},
{
fullname: 'John Doe',
phoneNumber: '0112255644',
status: true
},
{
fullname: 'Mark Doe',
phoneNumber: '0723567890',
status: true
},
{
fullname: 'John Doe',
phoneNumber: '0778904321',
status: true
},
{
fullname: 'Mark Doe',
phoneNumber: '0785674334',
status: true
},
{
fullname: 'Jaden Boor',
phoneNumber: '0713456980',
status: true
},
{
fullname: 'Mark Doe',
phoneNumber: '0112357654',
status: true
},
],
Othercalls: [
{fullname: 'Mark Doe', phoneNumber: '0112234567'},
{fullname: 'Clark Man', phoneNumber: '0723434567'},
{fullname: 'Jaden Boor', phoneNumber: '0778902356'},
]
};
在这里,我得到了“othercalls”数组的详细信息,并将状态更改为 false。但这不是我想要的。我需要比较这两个数组并仅在“othercalls”数组中的联系人中将状态值更新为 false。而且我还需要“调用”数组的完整数据。
let tempList = this.state.Othercalls.map(item => item.phoneNumber);
let result = this.state.calls.filter(item => (tempList.includes(item.phoneNumber)))
result.map((listItem, index) => {
listItem.status = false
})
我希望这个解决方案在这里解决我的问题:(How to compare two array in react native?)
【问题讨论】:
标签: arrays react-native react-native-flatlist