我目前正在研究中/大规模数据驱动的 Asp.net MVC应用程序的前端,我对正确的代码组织/设计模式有所怀疑.Web应用程序由多个页面组成,其中包含使用Razor模板定义的许多Kendo UI MVC小部件.
对于那些不熟悉Kendo的人,剃刀语法被翻译为Javascript,如下面的片段:
我在我的脚本文件夹中定义了两个主要文件夹,我按如下方式构建了我的js文件:
shared //包含共享的js文件-file1.js -file2.js
页面//每页一个文件
每个js文件都是使用以下模式定义的单独模块:
注意:内部init
函数将每个回调函数注册到窗口事件,偶尔也会注册一个$(document).ready(function(){})
块.
;(function () {
"use strict";
function Ticket(settings) {
this.currentPageUrls = settings.currentPageUrls;
this.currentPageMessages = settings.currentPageMessages;
this.currentPageEnums = settings.currentPageEnums;
this.currentPageParameters = settings.currentPageParameters;
this.gridManager = new window.gridManager(); //usage of shared modules
this.init();
}
Ticket.prototype.init = function () {
$("form").on("submit", function () {
$(".window-content-sandbox").addClass("k-loading");
});
...
}
Ticket.prototype.onRequestStart = function (e) {
...
}
//private functions definition
function private(a, b, …
Run Code Online (Sandbox Code Playgroud)