React / Redux - 如何将值从redux存储传递到onClick处理程序

时间:2017-07-26 13:12:57

标签: reactjs react-redux

我有一个组件,其中我有一个函数,通过来自redux的FieldsArray呈现位置列表,我试图弄清楚如何访问称为{{1}的属性当从父组件设置_id时?

这是我的功能,用于呈现列表:

initialValues

然后供参考:

renderLocations({ fields, meta: { touched, error, submitFailed } }) {
      return (
        <div>
          <div className={styles.contactInfoSection}>
            <h2>Locations</h2>
            <div>
              <button type="button" className={styles.add} onClick={() => fields.push({})}>Add Location</button>
              {(touched || submitFailed) && error && <span>{error}</span>}
            </div>
          </div>
          <ul className={styles.locationsList}>
            {fields.map((location, index) =>
              <li className={styles.locationCard} key={index}>
                <div>
                  <Field
                    name={`${location}.street`}
                    hintText="Street"
                    component={TextField}
                    label="Street"/>
                  <Field
                    name={`${location}.city`}
                    hintText="City"
                    component={TextField}
                    label="City"/>
                  <Field
                    name={`${location}.state`}
                    hintText="State"
                    component={TextField}
                    label="State"/>
                  <Field
                    name={`${location}.zip`}
                    hintText="Zip"
                    component={TextField}
                    label="Zip"/>
                </div>
                <button
                  type="button"
                  title="Remove"
                  onClick={() => {
                    fields.remove(index);
                    this.removeLocation(<locationId?>); // I need to be able to pass in an _id from the initialValues here
                  }}>Remove</button>
              </li>
            )}
          </ul>
        </div>
      );
    }

<ManageCustomerForm initialValues={this.state.customer} /> 有一个this.state.customer属性,该属性映射到包含该位置locations的对象数组,以及其他一些数据。

0 个答案:

没有答案