Home > front end >  [discuss] simple ASP MVC development pattern.
[discuss] simple ASP MVC development pattern.

Time:04-03

Code only to realize the MVC pattern and json processing, is not a framework, is to explore whether this pattern will help clarify development ideas,
Handled separately realized modularity, web and API, providing API debug page,
 & lt; % @ Language="JavaScript" codepage="65001" % & gt; <% 
//boot
The function the boot () {
Var route=(Request. The QueryString (" r "). The Item | | ""). The split ("/");
Var model=getModel (route), c=0;
While (true) {
Var op=(route [] c + + | | "List"). The toLowerCase ();
if(! Model (op)) return tojson ({err: "403 Object Not Found"});
If (" function "!=typeof model (op)) {model=model (op); continue; }
Var rs=model (op) ();
Return the rs instanceof Object? Tojson (rs) : rs;
}
}

//module definition
The function getModel (route) {
//display the API interface debugging interface
Var showApi=function (apipath) {
if(! Apipath) apipath="Api";
Sys. Apipath="? R="+ (Request. The QueryString (" r"). The item | | ""). The replace (/\ w + $/," ") + apipath + "/".
//can be downloaded from here: http://boomstone.net/AspLib/views/apidoc.html
% & gt; };
Var root={
//classification module
Cata: {
API: {
Memo: [" classification ", "as well as the ajax call, also can through this. API calls,"],
ListDoc: [" category List ", "","? R=Cata/Api/List "],
List: the function () {return {rows: new Array}; },
ShowDoc: [" classification view "],
Show: the function () {return {title: "data from view the interface"}; },
SaveDoc: [" classification "],
The save: function () {return {MSG: "save OK."}; },
DropDoc: [" classification delete "],
Drop: the function () {return {MSG: "drop OK."}; }
},
List: the function () {
Var rs=this. API. The list ();
Return here include classification list template page: "" + tojson (rs);
},
//? R=Cata/Show/5
Show: the function () {
Var rs=this. API. The show ();
Return "Cata Show ID [" + ~ ~ the route [2] +"] : "+ tojson (rs);
},
//? R=Cata/ApiDoc
Apidoc: function () {return showApi. Call (enclosing the API); }
},
//information module
Info: {
API: {
List: the function () {return {rows: new Array}; },
Show: the function () {return new Object; },
The save: function () {return {MSG: "save OK."}; },
Drop: the function () {return {MSG: "drop OK."}; }
},
List: the function () {return "Info list"; },
Show: the function () {return "Info show"; },
Apidoc: function () {return showApi. Call (enclosing the API); }
}
}
Return the root;
}

//global function definition
The function tojson (STR) {
If (sys. JSON) return sys. JSON. Stringify (STR);
Return the getJson (.) stringify (STR);
}

The function fromjson (STR) {
If (sys. JSON) return sys. JSON. Parse (STR);
Return the getJson (). The parse (STR);
}

The function getJson () {
Var doc=new ActiveXObject (" htmlfile ");
Doc. Write (" & lt; Meta HTTP - equiv='X - UA - Compatible content=' IE=edge/& gt;" );
Return sys. JSON=doc. Frames. JSON;
}

Var sys=new Object;
Response. Write (boot ());
% & gt;

CodePudding user response:

All functions are written routing, and routing module unlimited depth contrast, which is more appropriate? Each have advantages and disadvantages, feel a little bit small project, the primary routing should be enough, a larger projects, points module is more appropriate, but the ASP language, the feeling is a larger project is more suitable for use the new ASP file to do different module
  •  Tags:  
  • ASP
  • Related