資源描述:
《extjs動(dòng)態(tài)加載javascript創(chuàng)建窗體的方法_javascript技巧》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、ExtJS動(dòng)態(tài)加載JavaScript創(chuàng)建窗體的方法JavaScript不需要編譯即可運(yùn)行,這讓JavaScript構(gòu)建的應(yīng)用程序可以變得很靈活。我們可以根據(jù)需要?jiǎng)討B(tài)從服務(wù)器加載JavaScript腳本來(lái)創(chuàng)建和控制UI來(lái)與用戶交互。下面結(jié)合ExtJS來(lái)說(shuō)明如何從服務(wù)器上動(dòng)態(tài)加載JS腳本來(lái)動(dòng)態(tài)創(chuàng)建窗體。1項(xiàng)目結(jié)構(gòu):項(xiàng)目結(jié)構(gòu)如下:其中GetJSUI一般處理程序用來(lái)從數(shù)據(jù)庫(kù)表中抓取UI配置,并返回到客戶端;Contents文件夾下用HTML文件和JS庫(kù)等。硬解關(guān)方衾9對(duì)s6'(2個(gè)項(xiàng)目)A回CMCloudDBHelper/豹extjsSA?Properties>引用App^Data卜C
2、ontents亠Services丄晅)GetJSULashx>l5GetlSUI.ashx.esA胡Global.asax<0index.html匸packages.configD匸Web.config2數(shù)據(jù)庫(kù)表結(jié)構(gòu)可以用下面的SQL在MSSQL中創(chuàng)建表,其中JavaScriptContent字段存儲(chǔ)具體的JS腳木。CREATETABLE[dbo].[ExtDynamicForm]([ID][nvarchar](50)NOTNULL,[UniName][nvarchar](50)NULL,[JavaScriptContent][nvarchar](4000)NULL,[Memo]
3、[nvarchar](200)NULL,CONSTRAINT[PKExtDynamicForm]PRIMARYKEYCLUSTERED([ID]ASC))ON[PRIMARY]□二dbo.Ext_Dynamic_Form日口列?ID(PK,nvarchar(50),notnull)圍UniName(nvarchar(50),null)FlJavaSeriptContent(nvarchar(4000),null)[f]Memo(nvarchar(200),null)?口約束?_j鮭發(fā)器S□索引?統(tǒng)計(jì)信息創(chuàng)建好后,可以初始化數(shù)據(jù):囲結(jié)果消息IDUni...JavaScriptCon
4、tent1001Cm...Ext.onReadyfunctionf){varInvoiceModel=Ext.define(HlnvoiceM.{extend:MExt.data.Moc2002Cm...Ext.onRead)rfunotion0{varInvoiceModel=Ext.define(nlnvoicy,{extend:"Ext.data.Moc3003Cm...ExtonReadygunction。{varInvoiceModel=Ext.define「Invoice:{extend:HExt.data.Moc4004Cm...ExtonRead)rffuncti
5、onI){varInvoiceModel=Ext.define(HIrwoice:{extend:nExt.data.Moc5005Cm...Ext.onRead)rffunctionI){varInvoiceModel=Ext.define「lnvoice:{extend:"Ext.data.Moc6006Cm...ExtonReady?unction0{varInvoiceModel=Ext.define「lrwoice:{extend:,rExt.data.F1oc創(chuàng)建好后,可以初始化數(shù)據(jù):4GetJSUI編程usingSystem;usingSystem.Collect
6、ions.Gencric;usingSystem.Linq;usingSystem.Web;usingCMCloudDBHelper;namespaceextjs6.Services{//////author:jackwangcumt///publicclassGetJSUI:THttpHandler{publicvoidProcessRequest(HttpContextcontext)stringjs=context.Response.ContentType="text/plain";//context.Response.ContentT
7、ype=/ztext/javascript?/;CMCDataAccessda二newCMCDataAccess();stringSQLForJS二"select*FROMExt_Dynamic_FormwhereID二'006'〃System.Data.DataTablcdt=da.GetDataTablc(SQLForJS);if(dt!=null){if(dt.Rows.Count==l){js二dt.Rows[0][zzJavaScriptContent,z].ToStr