MVC 和 javascript 新方法;问:我以后使用这种方法可能会遇到问题吗?

发布于 2024-10-08 07:03:49 字数 2357 浏览 0 评论 0原文

我将解释我背后的想法: 我使用 python for google app engine + 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”这样的视图,那么“views”js var将有一个名为“login”的属性;视图['登录'] = '...内容...'; 示例2:“/views/admin/sexyBitcy.html”然后view['admin.sexyBitcy'] ='...content...'或该html文件中存在的任何内容..;
  3. 然后这个大文件将被保存到“/src/static_files/core.js”中;如果缩小将保存为“/src/static_files/core.min.js”;

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

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

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

// LoginController

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 应用程序来说,这是否可扩展、可管理且足够快?

谢谢;)

I will explain my idea behind this:
I use python for google app engine + js + css

the main project will be stored under the src folder like this:
\src
\app <--- here goes all the python app for gae
\javascript <--- my non-packed javascript files
\static_files <--- static files for gae

now the javascript dir looks like this

\javascript
\frameworks <--- maybe jQuery && jQueryUI
\models <--- js files
\controllers <--- js files
\views <--- HTML files!
app.js <--- the main app for js
compile.py <--- this is the file I will talk more

About compile.py:
This file will have 2 methods one for the min and other for the development javascript file;
When is run will do:

  1. Join all the files with "js" extension;
  2. The app.js contains a variable named "views" and is an object, like a hash; Then the compiler copy the contents of each file with "html" extension located in the "/javascript/views/" dir using this rule;
    example: if we have a view like this "/views/login.html" then the "views" js var will have a property named "login"; views['login'] = '...content...';
    example2: "/views/admin/sexyBitcy.html" then view['admin.sexyBitcy'] = '...content...' or whatever exists in that html file..;
  3. Then this big file will be saved into the "/src/static_files/core.js"; if is minified will be saved as "/src/static_files/core.min.js";

The javascript will use dependenccy injection, or sort of it. (:

I will explain how it will work then:

  1. the index.html that is loaded when you come into the site loads the core.js and the jquery.js;
  2. the core.js will create the layout of the page, as SEO is not important for the most of the pages;
  3. the core.js uses the controllers-models-views to create the layout of course; the html for the layout is inside the var "views"; will be a heavy variable of course!
  4. Some code:

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

jquery
view = mvcInjector.instanceView('login', parent); // <--- this will create the contents of the views['login'] in the parent node "parent = $('#jscontent');" then will instance the LoginController that will map the "SkinParts" (like in FLEX if you know); what does it mean map the "SkinParts"? - when the user will click on a button an handler for that action is defined in the controller; ex.:

// LoginController

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());
}

If something is not clear just say something, I will be happy to explain;
So the question remains: is this scalable, manageable and fast enough for a big RIA application build with javascript+jquery and maybe with jqueryUI?

Thanks ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师 2024-10-15 07:03:49

我喜欢你的想法,放弃一点。

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

看看 Angular 项目,我希望它可以对你有很大帮助。它是一种 JS 框架,旨在与 jQuery 一起工作。非常适合测试驱动开发。
它使用 html 作为模板,您可以简单地创建自己的控制器、使用依赖注入器等...请随时在 邮件列表

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

I like your idea quit a bit.

I would think about loading html pages by ajax, if they are big and there are many of them...

Have a look on angular project, I hope, it could help you a lot. It's a kind of JS framework, designed to work together with jQuery. Well suitable for test driven development.
It uses html as templates, you can simply create your own controllers, use dependency injector, etc... Feel free to ask any question on mailing list.

Then, I must recommend JsTestDriver - really cool test runner for JS (so you can easily run unit tests in many browsers, during development - let's say after save...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文