資源描述:
《ajax in action the page as an application》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、iTePub.Net-CollectThepageasanapplicationThischaptercovers■Organizingcomplexuserinterfacecode■UsingtheModel-View-ControllerpatternwithJavaScript■Separatingpresentationfromlogicformaintainablecode■Creatingaflexibleevent-handlingmode■Generatingtheuserinterfacedirectlyfromyourbusinessobject
2、s119LicensedtojonathanzhengiTePub.Net-Collect120CHAPTER4ThepageasanapplicationInchapters1and2wecoveredthebasicprinciplesofAjax,frombothausabilityandatechnologyperspective.Inchapter3wetouchedonthenotionofcreatingmaintainablecodethroughrefactoringanddesignpatterns.Inth
3、eexamplesthatwe’velookedatsofar,thismayhaveseemedlikeoverkill,butasweexplorethesubjectofAjaxprogramminginmoredepth,theywillprovethemselvestobeindispensabletools.Inthischapterandthenext,wediscussthedetailsofbuildingalarger,scal-ableAjaxclient,andthearchitecturalprinciplesneededtomakeitwo
4、rk.Thischapterlooksatthecodingoftheclientitself,drawingheavilyontheModel-View-Controller(MVC)patternthatwediscussedinchapter3.We’llalsoencoun-tertheObserverandothersmallerpatternsalongtheway.Chapter5willlookattherelationshipbetweentheclientandtheserver.4.1AdifferentkindofMVCInchapter3,w
5、epresentedanexampleofrefactoringasimplegarmentstoreapplicationtoconformtotheMVCpattern.ThisisthecontextinwhichmostwebdeveloperswillhavecomeacrossMVCbefore,withtheModelbeingthedomainmodelontheserver,theViewthegeneratedcontentsenttotheclient,andtheControlleraservletorsetofpagesdefiningthe
6、workflowoftheapplication.However,MVChaditsoriginsindesktopapplicationdevelopment,andthereareseveralotherplacesinanAjaxapplicationwhereitcanserveuswelltoo.Let’shavealookatthemnow.4.1.1RepeatingthepatternatdifferentscalesTheclassicwebMVCmodeldescribestheentireapplicationincoarse-grainedde
7、tail.TheentiregenerateddatastreamistheView.TheentireCGIorservletlayeristheController,andsoon.Indesktopapplicationdevelopment,MVCpatternsareoftenappliedatamuchfinerscale,too.SomethingassimpleasapushbuttonwidgetcanuseMVC:■Theinternalrepresentationofstates—pressed,unpressed,inacti