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

349 个评论

  1. Check out 1this guide abouthow to get free diamonds in cooking fever

    k23lartds11
    Cooking Fever is more fun when you have as many diamonds as you want.If you love phone games like this you need to check out this site

    JimRow
  2. Check out 1this guide about how to get free diamonds on cooking fever

    gddd23jas
    Cooking Fever is a lot more fun when you have as many diamonds as you could ever want.If you like phone games like this you should check out the website above

    JimRow
  3. Hey, we are running a black friday special on leads..

    The entire USA (93 million records for $79)
    The entire Australia (8 million records for AUD 99)
    The entire South African Database (4 Million records for R1000)
    The entire UK (16 million records for £49)

    Or take all 152 countries for $99!

    Instant access and delivery. Visit CompanyLeads.org

    Regards,
    Jayden

    Reay
  4. Hey, are you starving to find the right leads?

    CompanyLeads.org has launched a limited time offer that covers all the countries in the world.

    At $149 once-off you get access to over 300 million leads categorized, targetted and ideal.

    Instant access and delivery. Visit CompanyLeads.org

    Regards,
    Sherlyn

    Guidry
  5. Hi ,

    Who would I contact at your company that handles ordering your logo products, t-shirts, and promotional items?

    For over 20 years we have been creating and supplying our clients with all their custom logo merchandise.

    We can put your logo onto anything including:

    -Custom Printed T-shirts / Hoodies
    -Pens
    -Mugs
    -T-shirts
    -Bags
    -Banners
    -Table Covers
    -Key chains
    -USB flash drives

    —plus 350,000 other items!

    We also offer PPE items such as hand sanitizer and masks.

    Are there any upcoming projects that you need logo items for?

    Thanks in advance for your time.

    Regards,

    Bernard
    Custom Branded Product Specialist

    Bushby
  6. Hello,

    My name is Johan, I am a PHP programmer that specializes in data driven web applications.

    Anything related to PHP, MySQL, Data scraping etc.

    If you have any custom jobs you can add me on skype to discuss your requirements.

    Skype: cmsdevelopers

    Regards,
    Johan

    Fourie
  7. Hi from Order-Fulfillment.net

    Who would I speak with at your company about any of your order fulfillment and drop shipping needs?

    My company Order-Fulfillment.net can warehouse, inventory, and manage your drop shipping / order fulfillment for your customer orders.

    Based in the USA for almost 2 decades, near major USA air and sea ports.

    Here are some of the items we currently pick, pack and ship for clients:

    -Books, training manuals, guides
    -New member welcomes boxes and gifts
    -Product samples
    -Marketing materials
    -Medical program test kits
    -Follow up gifts to clients, leads, and prospects

    Thank you!

    Fulfillment Warehouse
    Order-Fulfillment.net
    Drop Shipping and Order Fulfillment Specialists since 2003

    Mascorro
  8. Right here is the right website for anybody
    who wants to understand this topic. You know a whole
    lot its almost hard to argue with you (not that I really will need to…HaHa).
    You definitely put a fresh spin on a topic that’s been discussed for a long time.

    Wonderful stuff, just excellent!

  9. Hi there! I know this is somewhat off-topic but I needed to ask.

    Does building a well-established blog like yours take a massive amount work?

    I am completely new to operating a blog however I do
    write in my journal everyday. I’d like to start a
    blog so I can share my experience and thoughts online.
    Please let me know if you have any kind of ideas or
    tips for brand new aspiring blog owners. Thankyou!

  10. Hello,

    It is with sad regret to inform you that BestLocalData.com is shutting down.

    We have made all our databases for sale for a once-off price.

    Visit our website to get the best bargain of your life. BestLocalData.com

    Regards,
    Gene

    Harkness
  11. Hello,

    It is with sad regret to inform you that BestLocalData.com is shutting down.

    We have made all our databases for sale for a once-off price.

    Visit our website to get the best bargain of your life. BestLocalData.com

    Regards,
    Renate

    Clausen
  12. Are you looking for the best way to market your business?

    FbCourses.net has the answer..

    Not sure where to start, or what to do?

    Why not learn from the best. All of the best.

    We are offering at never before seen prices all of the top courses for one insanely low price.

    If you have been thinking of how to generate more leads, website traffic or sales today is the day.

    All courses are available in full with immediate download on FbCourses.net

    Not sure which one you like, for the next 24 hours we are offering the entire suite of courses for the lowest amount you could possible imagine.

    Check us out : FbCourses.net

    You could be driving new income or starting the new side hustle today!

    Libby

发表评论

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