ant D源码中form组件只对是react-component form的一层封装

首先表单是双向绑定的

双向绑定,廖雪峰老师是这样解释的

form在react中是怎么实现数据的双向绑定的?

在react中我们可以手动去绑定input框的值为一个state中的值,然后每次onchange时去更新state

刚看到createBaseForm.js的源码时,我猜测,reactForm也是这样实现的

默认的触发器就是onchange,再来看实现流程是怎么样的

createBaseForm返回一个高阶函数decorate

这里采用es5的类写法,getInitialState相当于Es6 Class中的constructor部分,在生成一个表单实例时就会有一个fieldsStore对象,通读全文后发现,很多复杂操都是在对这个全局store进行维护

getFieldDecorator是一个高阶函数,将传入的组件封装后返回

  • 核心部分onChange的封装

在onCollect部分先通过onCollectCommon实现了原action也就是onChange的执行,再setFields更新当前表单的值

更新store后,强制刷新

这里已经能够大概知道form内部是怎么运作的了,我画了一张流程图

根据原理做了一个简单的demo

  • npm

https://www.npmjs.com/package/zjx-react-form

  • 码云

https://gitee.com/onezilc/my-react-form.git

369 个评论

  1. Hello from BestLocalData.com

    Due to the pandemic BestLocalData.com is shutting down on the 14th of May.

    We have more than a 100 million records of Key Executives all over the world.

    We hope that this Data will serve other companies to succeed in their marketing efforts.

    We have reduced all the prices to next to nothing on our website BestLocalData.com

    We wish you the best in your future endeavours.

    Bowles
  2. Hello from SendBulkMails.com,

    We have a special limited offer for you to send unlimited emails.

    We allow non-permission based emails and you won’t ever get blocked.

    We also buy your domain for you and give you a clean IP and setup your DNS records.

    Check us out on SendBulkMails.com

    Tripp
  3. Do you need clients?

    We compiled some of the world’s top databases for you at ridiculous low prices. $49 for any of our databases or $99 for all 16 databases!

    Visit BestLocalData.com

    Regards,
    Valeria

    Kozak
  4. Hey,

    It was nice speaking to you the other day, this is the service I was telling you about that helped us boost our ROI almost 2000%

    Its a company called Lifemail.studio sorry it took so long to get back to you. They allow you to send any email doesn’t matter what.

    We dealt with a guy named Michael, he was friendly and got us setup really quickly.

    Regards,
    Vickey

    Truman
  5. Hello,

    BestLocalData.com has a special package you get any group of databases for $49 or $249 for all 16 databases and unlimited emails for a year(Domain, IP, Dashboard included).

    You can purchase it on BestLocalData.com and see samples if you are interested.

    Pinckney
  6. Use SendBulkMails.com to run email campaigns from your own private dashboard.

    Cold emails are allowed and won’t get you blocked 🙂

    – 1Mil emails / mo @ $99 USD
    – Dedicated IP and Domain Included
    – Detailed statistical reports (delivery, bounce, clicks etc.)
    – Quick and easy setup with extended support at no extra cost.
    – Cancel anytime!

    Regards,
    http://www.SendBulkMails.com

    Utley
  7. It is with sad regret to inform you StarDataGroup.com is shutting down.

    Fire sale till the 7th of Feb.

    Any group of databases listed below is $49 or $149 for all 16 databases in this one time offer.
    You can purchase it at http://www.StarDataGroup.com and view samples.

    – LinkedIn Database
    43,535,433 LinkedIn Records

    – USA B2B Companies Database
    28,147,835 Companies

    – Forex
    Forex South Africa 113,550 Forex Traders
    Forex Australia 135,696 Forex Traders
    Forex UK 779,674 Forex Traders

    – UK Companies Database
    521,303 Companies

    – German Databases
    German Companies Database: 2,209,191 Companies
    German Executives Database: 985,048 Executives

    – Australian Companies Database
    1,806,596 Companies

    – UAE Companies Database
    950,652 Companies

    – Affiliate Marketers Database
    494,909 records

    – South African Databases
    B2B Companies Database: 1,462,227 Companies
    Directors Database: 758,834 Directors
    Healthcare Database: 376,599 Medical Professionals
    Wholesalers Database: 106,932 Wholesalers
    Real Estate Agent Database: 257,980 Estate Agents
    Forex South Africa: 113,550 Forex Traders

    Visit http://www.stardatagroup.com or contact us with any queries.

    Kind Regards,
    StarDataGroup.com

    Saville
  8. It is with sad regret to inform you StarDataGroup.com is shutting down.
    It has been a tough year all round and we decided to go out with a bang!

    Any group of databases listed below is $49 or $149 for all 16 databases in this one time offer.
    You can purchase it at http://www.StarDataGroup.com and view samples.

    – LinkedIn Database
    43,535,433 LinkedIn Records

    – USA B2B Companies Database
    28,147,835 Companies

    – Forex
    Forex South Africa 113,550 Forex Traders
    Forex Australia 135,696 Forex Traders
    Forex UK 779,674 Forex Traders

    – UK Companies Database
    521,303 Companies

    – German Databases
    German Companies Database: 2,209,191 Companies
    German Executives Database: 985,048 Executives

    – Australian Companies Database
    1,806,596 Companies

    – UAE Companies Database
    950,652 Companies

    – Affiliate Marketers Database
    494,909 records

    – South African Databases
    B2B Companies Database: 1,462,227 Companies
    Directors Database: 758,834 Directors
    Healthcare Database: 376,599 Medical Professionals
    Wholesalers Database: 106,932 Wholesalers
    Real Estate Agent Database: 257,980 Estate Agents
    Forex South Africa: 113,550 Forex Traders

    Visit http://www.stardatagroup.com or contact us with any queries.

    Kind Regards,
    StarDataGroup.com

    Stahlman

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注