React-native-contact updateContact正在更新1个联系人的所有电话号码,而不是特定号码

mok*_*211 5 android react-native react-native-android

我们有一个用React-Native编写的移动应用程序,并且使用了本指南中的模块React-native-contact:https : //github.com/rt2zz/react-native-contacts

该应用程序的目的是将数字的前缀从XXX更改为YYY。

联系人人数众多,并且一切正常。但是,我们要为一个联系人更新1个特定的号码,但是很遗憾,它正在更新该联系人的所有号码。我们可以通过以下代码获取在通讯录中找到的联系人列表:

 handleUpdate = () => {
 //phoneContacts => all the contacts found in the address book
 //contactDetails => all the contacts that have the prefix number that needs to be replaced. 
 //prefixNumber => is the prefix number that user wants to replace.
 const { phoneContacts, contactDetails, prefixNumber } = this.state;
 var updated_select = 0;
 var record = null;

  Contacts.getAll( (err, contacts) => {

  _.forEach(contactDetails, (contactD) => {

    if (contactD[1] == true) {

      //where contactD[5] is the specific phone number
       var num = contactD[5];
       num = num.replace(prefixNumber, '010');

      _.forEach(contacts, (cont) => {
         if (cont.recordID === contactD[0])
            //finding the record to be updated in the Contact List
            record = cont;
       });

       //Replacing the record phone numbers with the updated one. 
       record.phoneNumbers[contactD[3]] = { label: contactD[4], number: num };

       //Updating the contacts as per the guide linked above
       Contacts.updateContact(record, (err) => {
         if (err) {
           _alert('error', 'Application error: Update unsuccessful.');
           return;
         }
       });
        ++updated_select;
       }

  });

  ToastAndroid.show(updated_select + ' rows have been updated', ToastAndroid.SHORT);
   this.handleSearchContacts();
   return;
 });
}
Run Code Online (Sandbox Code Playgroud)

因此作为一个具体的例子。如果用户X已将前缀号码从555更改为010,

phoneNumbers: [
   {label: "work",number: "(555) 555-5555"},
   {label: "mobile",number: "(444) 444-4444"},
  ],
Run Code Online (Sandbox Code Playgroud)

更新时,应用程序会将用户X的两个数字都更新为:

 phoneNumbers: [
       {label: "work",number: "(010) 555-5555"},
       {label: "work",number: "(010) 555-5555"},
      ],
Run Code Online (Sandbox Code Playgroud)

我们还尝试推送所有值,包括已更新的记录,但所有数字均已更新。

在调试过程中,我们验证了变量record的值,并显示了带有所有详细信息的联系人,并且正确更新了特定的电话号码。

有任何想法吗?