简体   繁体   中英

How I can update array field value in redux-form?

isMain = (v, k) => {

    let {avatars: {fields}, push} = this.props;

    fields.getAll().map((avatar, key) => {

      fields.remove(key);

      push('avatars', {
        deleteImage: avatar.deleteImage || false,
        uuid: avatar.uuid,
        fileName: avatar.fileName,
        url: avatar.url,
        setMain: key === k,
      });

    });

};

This is how I try^ Doesn't work, I don't know why

I use v6

I also tried insert

But with insert field not removed only - copied! Although the value of new fields changed

if you only want to update a single item in array avatars , an alternative solution is using redux-form's Action Creators . Just need to provide the index value to action:

import { change } from 'redux-form'
...
setMain: (k) => dispatch(change(`yourForm`, `avatars[${k}].setMain`, true))

You can create another action removeMain(k) in the same manner to remove the old main avatar item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM