gpt4 book ai didi

javascript - MVC 和 javascript 新方法;问 : May I have problems in future with this approach?

转载 作者:行者123 更新时间:2023-11-28 10:25:32 26 4
gpt4 key购买 nike

我将解释我的想法:我使用 python 作为谷歌应用程序引擎 + js + css

主项目将存储在 src 文件夹下,如下所示:\src \app <--- 这里是 gae 的所有 python 应用程序 \javascript <--- 我的未打包的 javascript 文件 \static_files <--- gae 的静态文件

现在 javascript 目录看起来像这样

\javascript \frameworks <--- 也许是 jQuery && jQueryUI \models <--- js 文件 \controllers <--- js 文件 \views <--- HTML 文件! app.js <--- js 的主要应用程序 compile.py <--- 这是我将详细讨论的文件

关于compile.py:该文件将有 2 种方法,一种用于 min,另一种用于开发 javascript 文件;什么时候运行就可以了:

  1. 连接所有扩展名为“js”的文件;
  2. app.js 包含一个名为“views”的变量,它是一个对象,就像哈希一样;然后编译器使用此规则复制位于“/javascript/views/”目录中的每个扩展名为“html”的文件的内容;例如:如果我们有一个像“/views/login.html”这样的 View ,那么“views”js var将有一个名为“login”的属性; View ['登录'] = '...内容...';示例2:“/views/admin/sexyBitcy.html”然后view['admin.sexyBitcy'] = '...content...'或该html文件中存在的任何内容..;
  3. 然后这个大文件将被保存到“/src/static_files/core.js”中; if 缩小后将保存为“/src/static_files/core.min.js”;

JavaScript 将使用依赖注入(inject)或类似的方式。 (:

我将解释它是如何工作的:

  1. 当您进入网站时加载的index.html会加载core.js和jquery.js;
  2. core.js 将创建页面布局,因为 SEO 对于大多数页面来说并不重要;
  3. core.js 当然使用controllers-models-views 来创建布局;布局的 html 位于 var“views”内;当然,这将是一个很大的变量!
  4. 一些代码:

    mvcInjector = new MVCInjector;mvcInjector.mapView(views['login'], 'login', LoginController);parent = $('#jscontent');

jquery view = mvcInjector.instanceView('登录', 父级);//<--- 这将在父节点中创建 View ['login']的内容 "parent = $('#jscontent');"然后将实例化 LoginController 来映射“SkinParts”(如果你知道的话,就像在 FLEX 中一样);映射“SkinParts”是什么意思? - 当用户单击按钮时, Controller 中定义该操作的处理程序;例如:

//登录 Controller

this.init = function(){
// map skin parts
this.mapSkinPart('email', 'input[name]="email"');
this.mapSkinPart('submit', 'input[name]="submit"');

// link skin parts to handlers
this.getSkinPart('submit').click = this.login;
}

// handlers
this.login = function(event){
// connect to the db
// some problems here the get the value as the "this" keyword references to the this of the controller class, I will work it around soon
alert('open window button1' + this.getSkinPart('email').value());
}

如果有不清楚的地方,请说出来,我很乐意解释;所以问题仍然是:对于使用 javascript+jquery 甚至 jqueryUI 构建大型 RIA 应用程序来说,这是否可扩展、可管理且足够快?

谢谢;)

最佳答案

我喜欢你的想法,稍微放弃一下。

我会考虑通过ajax加载html页面,如果它们很大并且有很多......

看看angular项目,我希望它可以帮助你很多。它是一种 JS 框架,旨在与 jQuery 一起工作。非常适合测试驱动开发。它使用 html 作为模板,您可以简单地创建自己的 Controller 、使用依赖注入(inject)器等...如有任何问题,请随时在 mailing list 上提出。 .

那么,我必须推荐JsTestDriver - 非常酷的 JS 测试运行程序(因此您可以在开发过程中轻松地在许多浏览器中运行单元测试 - 比如说保存后...)

关于javascript - MVC 和 javascript 新方法;问 : May I have problems in future with this approach?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4455053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com