Ext JS dynamically loads JavaScript to create a form, extjavascript

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.