如圖:每一條記錄點擊編輯的時候form顯示相應的記錄的值,我的做法是點擊編輯獲取記錄的record存在state.formData中,如何把state.formData當做props參數(shù)傳遞給form組件,form組件的初始值從this.props.formData里面取。
問題是:我如果只點擊編輯然后關掉,再點擊其他記錄的編輯顯示是沒有問題的。但是只要我點擊編輯,修改了input的值,關閉以后。再點擊其他任何記錄,form顯示的都是剛剛修改了然后關閉了的記錄。
比如:選擇某一條修改兩處為test之后,沒有點擊確定直接點擊關閉。
如何點擊其他所有記錄都變成了這樣:
我在form的render函數(shù)下面打印了接受到的props.formData參數(shù)是沒有問題的,是記錄傳遞過來的值,但是顯示的時候有問題:
這個是整個form的代碼
import React from 'react';
import { Form , Input , Button } from 'antd';
const FormItem = Form.Item;
const formItemLayout = {
labelCol : {span : 5},
wrapperCol : {span : 15}
};
class FormLayout extends React.Component{
handleSubmit(e){
e.preventDefault();
this.props.comfirmHandle(this.props.form.getFieldsValue()); //獲取當前表單數(shù)據(jù)并當做回調(diào)函數(shù)的參數(shù)傳遞給父組件
}
// componentWillReceiveProps(nextProps){
// if(!nextProps.visible){
// this.props.form.resetFeilds();
// }
// }
render(){
const { getFieldDecorator ,getFeildsValue } = this.props.form;
const { record } = this.props;
return (
<Form onSubmit= {this.handleSubmit.bind(this)}>
<FormItem label="編號" {...formItemLayout}>
{getFieldDecorator('id', {
rules: [{ required: true, message: '請輸入書籍編號!' }],
initialValue : record ? record.id : ""
})(
<Input placeholder="請輸入書籍編號"/>
)}
</FormItem>
<FormItem label="名稱" {...formItemLayout}>
{getFieldDecorator('name', {
rules: [{ required: true, message: '請輸入書籍名稱!' }],
initialValue : record ? record.name : ""
})(
<Input placeholder="請輸入書籍名稱"/>
)}
</FormItem>
<FormItem label="價格" {...formItemLayout}>
{getFieldDecorator('price', {
rules: [{ required: true, message: '請輸入價格!' }],
initialValue : record ? record.price : ""
})(
<Input placeholder="請輸入價格"/>
)}
</FormItem>
<FormItem label="借閱者編號" {...formItemLayout}>
{getFieldDecorator('owner_id', {
rules: [{ required: true, message: '請輸入借閱者編號!' }],
initialValue : record ? record.owner_id :""
})(
<Input placeholder="請輸入借閱者編號"/>
)}
</FormItem>
<FormItem wrapperCol={{ span: 10, offset: 10 }}>
<Button type="primary" htmlType="submit">
確定
</Button>
</FormItem>
</Form>
);
}
}
export default FormLayout = Form.create()(FormLayout);
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學院和江蘇省首批服務外包人才培訓基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務機構(gòu),發(fā)展為教育服務業(yè)的綜合性企業(yè)集團,成為集合面授教學培訓、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務負責iOS教學及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。