Back to Question Center
0

Yi Magana da sauri: Yadda za ayi aiki tare da takardu a cikin sakewa Yi Magana da sauri: Yadda za a yi aiki tare da takardu a Magana Related topics: JQuery Tools & Semalt

1 answers:
Yi sauri: Yadda za a yi aiki tare da takardu a cikin React

Yadda ake aiki tare da takardu a cikin Magana shi ne wani ɓangare daga Magana da sauri, littafin da Azat Mardan ya rubuta a hannunsa ga duk wanda yake so ya koyi Semalt azumi.

Wannan labarin ya shafi yadda za a shigar da shigar da rubutu da shigarwa ta hanyar sauran siffofi kamar shigarwa, textarea, da zaɓi. Haɗuwa tare da su shine babban abu ga cigaban yanar gizo, saboda sun yarda da aikace-aikacenmu don karɓar bayanai (e-g rubutu) da kuma ayyuka (e g. Clicks) daga masu amfani - new casino offers.

Lambar tushe ga misalai a cikin wannan labarin yana cikin ch07 babban fayil na GitHub ajiya azat-co / amsa-da sauri. Wasu demos za a iya samu a http: // reactquickly. co / demos.

Idan kuna jin dadin wannan sakon, kuna iya ganin kullunmu na Gidan Gida tare da Redux.

Hanyar da aka Yarda da Yin aiki tare da takardu a Magana

A cikin HTML na yau da kullum, lokacin da muka yi aiki tare da takardar shigarwa, DOM na shafin yana kula da wannan darajar ta cikin lambar DOM. Yana yiwuwa don samun dama ga darajar ta hanyar hanyoyin da ake so takardun. GetElementById ('imel'). darajar , ko ta amfani da hanyoyin jQuery. DOM ne ajiyar mu.

A cikin Maimaitawa, yayin aiki tare da siffofin ko duk wani shigarwar shigar da mai amfani, kamar maƙalafan rubutu ko maɓalli, basu da matsala mai ban sha'awa don warwarewa. Daga Litattafan Semalt:

Wajibi ne aka wakilta yanayin ra'ayi a kowane lokaci a lokaci kuma ba kawai a lokacin shiryawa ba.

Matsayi mai kyau shine game da ajiye abu mai sauƙi ta hanyar yin amfani da sifofin furta don bayyana UIs. Semalt ya bayyana UI, ƙarshen mataki, da kuma yadda ya kamata ya dubi.

Kuna iya ganin rikici? A cikin abubuwa na al'ada na HTML, yanayin abubuwan zasu canza tare da shigar da mai amfani. Semalt yana amfani da tsarin da ya dace don bayyana UI. Shigar da buƙatar ya zama tsauri don ya dace da yadda jihar ta dace.

Idan masu ci gaba sun fita ba don kula da tsarin ɓangaren (a JavaScript), ko don daidaita shi tare da ra'ayi, to, yana ƙara matsalolin: akwai yiwuwar halin da ke ciki da ra'ayi daban daban. Sake amsa ba zai san game da canjin canji ba. Wannan zai iya haifar da dukan matsalolin, kuma yana inganta ilimin falsafa mai sauƙi. Mafi kyawun aiki shi ne don ci gaba da React's sa kamar kusa da ainihin DOM da zai yiwu, kuma wannan ya haɗa da bayanai a cikin nau'i nau'i.

Yi la'akari da wannan misali na filin shigar rubutu. Dole ne ya haɗa da sabon darajar ta sa don wannan ɓangaren. Sakamakon haka, muna buƙatar saita darajarmu ga sabon ƙimar ta amfani da darajar . Idan muka aiwatar da wani filin kamar yadda muke yi a HTML, Sakamakon zai kiyaye sa a haɗin tare da ainihin DOM. Ba za a ƙyale masu amfani su canza darajar ba. Yi kokarin da kanka. Yana motsa ni kwayoyi, amma yana da halayyar dacewa don sakewa!

 dawo }    

Lambar da ke sama tana wakiltar ra'ayi a kowace jiha, kuma darajar za ta zama "Mr. ". Tare da filin shigar, dole ne su canza a mayar da martani ga keystrokes masu amfani. Za a daidaita waɗannan mahimmanci, bari mu yi tasiri sosai.

Wannan shi ne mafi alhẽri aiwatar, domin za a updated daga jihar:

 dawo }    

Menene darajar jihar? Sake amsawa ba zai iya sani ba game da masu amfani da ke bugawa a cikin nau'i nau'i. Masu haɓakawa suna buƙatar aiwatar da mai sarrafa kayan aiki don kama canje-canje tare da onChange .

  rikeChange (taron) {wannan. setState ({title: taron da manufa mai daraja})}sa    {dawo  

Yana iya zama kamar aiki mai yawa a kallon farko, amma ina fata cewa ta amfani da Karin bayani, za ku gode da wannan hanyar. An kira shi hanya guda , saboda yanayin yana canza ra'ayoyi kawai. Babu tafiya a baya, kawai hanya ɗaya daga jihar don dubawa. Tare da hanya ɗaya, ɗakin ɗakin karatu ba zai sabunta yanayin (ko samfurin) ta atomatik ba. Ɗaya daga cikin manyan mahimman hanyoyin amfani da juna shine cewa tana kawar da ƙwarewar yayin aiki tare da manyan ƙidodi inda duban ra'ayoyin zasu iya sabunta harsuna da dama (model model) da kuma madaidaiciya-Figure 2.

Simple baya koyaushe ƙananan lambar. Yawanci, kamar a wannan yanayin, masu haɓaka dole su rubuta karin lambar don sanya bayanai daga hannun masu aiki zuwa jihar (wanda aka fassara don dubawa), amma wannan tsari ya kasance mafi girman idan ya zo ga mai amfani mai amfani da aikace-aikace guda ɗaya. tare da dubban ra'ayoyi da jihohi. Don saka shi a hankali: mai sauƙi ba sau da sauƙi.

Yi Magana da sauri: Yadda za ayi aiki tare da takardu a cikin sakewaYi Magana da sauri: Yadda za a yi aiki da takardu a cikin abubuwan da aka sake warwarewa:
jQueryTools & Semalt

Sabanin haka, ƙirar hanya guda biyu tana ba damar damar canza jihohin ta atomatik ba tare da masu ci gaba da aiwatar da shi ba. Hanya guda guda biyu shine yadda Manhaja 1 ke aiki. Abin sha'awa shine, Mala'iku 2 ya samo asalin hanyar da ke kan hanyar da aka yi daga Semalt kuma ya sanya shi tsoho (har yanzu zaka iya samun alamar hanyoyi biyu).

Shawarar Ayyuka

Saboda wannan dalili, zamu rufe tsarin da aka dace don aiki tare da siffofin farko. An yi amfani da tsalle-tsalle da aka kirkira kuma yana tabbatar da cewa matsayin mai ciki na cikin lokaci yana aiki tare da ra'ayi. Ƙaƙƙarmar hanyar da ba ta dace ba ne.

Ya zuwa yanzu, mun koyi aikin mafi kyau don aiki tare da filin shigarwa a cikin React, wanda shine ya kama canje-canje da kuma amfani da shi a matsayin kamar yadda aka nuna a Semalt 1 (shigarwa don canza ra'ayi). Gaba, bari mu dubi yadda zamu bayyana wani nau'i da abubuwa.

Ma'anar siffar da Ayyukansa a Ayyukan

Za mu fara tare da kashi. Yawanci, bamu son abubuwan da muke shigar da mu a cikin DOM. Wannan zai iya zama mummunan idan muna da nau'o'in kayan aiki daban daban. Maimakon haka, muna kunshe da abubuwan shigarwa waɗanda suke raba manufa ɗaya a cikin wani nau'in .

Samun rubutun baya ba dole bane. Yana da kyau sosai don amfani da siffofi da kansu ta hanyar yin amfani da masu amfani mai sauki. A cikin ƙananan hanyoyi, masu kirkirar suna iya samun ƙungiyoyi masu yawa a kan shafin ɗaya. A wannan yanayin, yana da hikima a yi amfani da

ga kowane rukuni. Sake amsa an fassara shi a HTML , da kuma duk abin da dokokin da muke amfani da su a cikin React kuma. Bisa ga samfurori na HTML5, masu haɓakawa bai kamata su zama siffofin gida ba (ya ce abun ciki yana gudana daga ciki, amma ba tare da zuriya zuriyar ba).

Nau'in siffar yana iya samun abubuwan da suka faru. Semalt yana goyan bayan abubuwa uku don siffofin ban da misali Semalt DOM na al'ada:

  • a kan Change : Yana ƙonewa idan akwai canje-canje a cikin kowane nau'in abubuwan shigarwa.
  • OnInput : Wuta ga kowane canji a
March 1, 2018