redux-form没有使用InitialValues对象

时间:2017-07-27 18:33:44

标签: redux-form react-redux-form

我正在使用react-redux-form 7.03并尝试从数据库填充字段。为了简化确定问题的位置,我创建了一个1对象的静态数组,试图获取要显示的信息。

我对React和Redux相当新,而且我已经和它斗争了三天了。我一直在使用https://codesandbox.io/s/qDjw3zGG中的示例和redux-forms示例而没有运气。

基本问题是在props中,我看到initialValue:xmlConfigDataSet,其中包含对象中的正确信息(正确填充了1个对象的数组)。但是,这不会传递给字段属性到RenderRows。调试字段显示长度为0,它只是通过map()并且从不渲染。

import React, {Component} from 'react'
import {connect} from 'react-redux'
import { Field, FieldArray, reduxForm } from 'redux-form'

class XMLMatchUpForm extends Component {
    constructor(props){
        super(props);
        this.state = {}
    }

    render(){
        return (
            <FieldArray name="xmlConfigDataSet" component={RenderRows} />
        )
};

const RenderRows = ({fields, meta}) => (
    <div>
        {fields.map((field, index) => {
            const value = fields.get(index);
            return <RenderStaticField name={field} value = {value} />
        })}
    </div>
)

const RenderStaticField = (props) => {
    <Field name={`${props.name}.MW_MD_VALUE`} component="input" />
}

XMLMatchUpForm =  reduxForm({
    form: "XMLMatchUpForm"
}) (XMLMatchUpForm);

function mapStateToProps(state) {
    return {
        initialValues: {
            xmlConfigDataSet:[{"MW_XS_ID":1314,"MW_MD_ID":null,"MW_XDM_VALUE":"Silver Spring","MW_XS_TAG_NAME":"receivercity"}]
    }
};
}

export default connect(mapStateToProps, {fetchXMLConfig}) (XMLMatchUpForm);

(忽略示例中的{fetchXMLConfig},这实际上是它正在为获取xmlConfigDataSet而进行的操作,如上所述,我正在尝试简化此操作以确定问题所在。

欢迎任何想法或明确示例的指示。

0 个答案:

没有答案
相关问题