Ext JS dynamically loads JavaScript to create a form, extjavascript
JavaScript can be run without compilation, which makes the applications built by JavaScript flexible. We can dynamically load JavaScript scripts from the server as needed to create and control the UI to interact with users. The following uses Ext JS to illustrate how to dynamically load JS scripts from the server to dynamically create a form.
1. project structure:
The project structure is as follows: GetJSUI is generally used to capture the UI configuration from the database table and return it to the client. HTML files and JS libraries are used in the Contents folder.
2. Database Table Structure
You can use the following SQL statement to create a table in MSSQL. The JavaScriptContent field stores specific JS scripts.
CREATE TABLE [dbo].[Ext_Dynamic_Form]( [ID] [nvarchar](50) NOT NULL, [UniName] [nvarchar](50) NULL, [JavaScriptContent] [nvarchar](4000) NULL, [Memo] [nvarchar](200) NULL, CONSTRAINT [PK_Ext_Dynamic_Form] PRIMARY KEY CLUSTERED ( [ID] ASC)) ON [PRIMARY]
After creation, you can initialize the data:
After creation, you can initialize the data:
4 GetJSUI Programming
using System;using System.Collections.Generic;using System.Linq;using System.Web;using CMCloudDBHelper;namespace extjs6.Services{ /// <summary> /// author:jackwangcumt /// </summary> public class GetJSUI : IHttpHandler { public void ProcessRequest(HttpContext context) { string js = ""; context.Response.ContentType = "text/plain"; //context.Response.ContentType = "text/javascript"; CMCDataAccess da = new CMCDataAccess(); string SQLForJS = "select * FROM Ext_Dynamic_Form where ID='006'"; System.Data.DataTable dt= da.GetDataTable(SQLForJS); if(dt!=null) { if(dt.Rows.Count==1) { js = dt.Rows[0]["JavaScriptContent"].ToString(); } } //utf-8 context.Response.ContentEncoding = System.Text.Encoding.UTF8; context.Response.Write(js); } public bool IsReusable { get { return false; } } }}
5 main interface html
<Html>
6. Run
In this way, we can build a main framework, and then build a general system such as menus and permissions. By configuring menus and UIS in the database, we can dynamically expand the application.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.