Vanilla JavaScript中的MVC [英] MVC in Vanilla JavaScript

查看:80
本文介绍了Vanilla JavaScript中的MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在处于这样的地步,我真的希望以一种使其更具可扩展性和可管理性的方式组织我的代码。我希望在不使用框架的情况下更好地理解javascript中的MVC架构。

I'm at the point now where i really want to organize my code in a way that makes it more scalable and manageable. i want to get a better understanding of the MVC architectural in javascript without using a framework.

所以这是我目前所理解的(如果我是的话请请纠正我)错误):

So this is what i understand thus far (please please please correct me if i'm wrong):

模型
网站/网络应用内容的有组织结构(图片,副本,可下载内容,等等...)
,在操作内容时也需要逻辑。所以在javascript中,模型可以是JSON对象,也可以是对检索/更新数据库的php文件的调用,模型的逻辑可以是负责解析,正则表达和组织内容的函数,这样就可以传递给它关闭视图?

Model: an organized structure of the sites/web apps content(pics, copy, downloadable content, etc...) that also has logic needed in the manipulation of the content. so in javascript the model could be a JSON object or a call to a php file that retrieves/updates a database and the model's logic could be functions that are responsible for parsing, regex-ing, and organizing the content so it can then be handed off to the view?

查看:用户界面和模型数据/内容的直观表示。它唯一的工作就是显示内容并接受用户输入(如果适用)?

View: the user interface and the visual representation of the Model's data/content. its only job is to display the content and accept user input if applicable?

控制器:所以控制器唯一的工作就是充当模型和视图之间的中介?例如,如果视图需要数据,它会询问控制器谁然后去模型获取数据然后将其发送回视图?如果有任何用户输入,视图会将其发送给控制器,控制器然后将其发送到模型,然后更新,然后控制器通知视图模型已经更新?

Controller: so is the controller only job is to act as a mediator between the model and the view? for instance, if the view needs data does it ask the controller who then go's to the model to get the data then sends it back to the view? and if there is any user input the view sends it to the controller who then sends it to the model which is then updated at which point the controller then informs the view that the model has then been updated?

对于我来说,MVC一直并且仍然是一个混乱的点,再加上它已经声明MVC在javascript中不是一个自然的事情(至少在php,java,actionscript中,等...)

MVC has been and still is a point of confusion for me, combined with the fact that its been stated that MVC is not a natural accuring thing in javascript(at lease not like in php,java,actionscript,etc...)

推荐答案

查看代码一直是我学习的最佳方式,所以我想我会分享这些。

Looking at code has always been the best way for me to learn so I figured I would share these.

TODO mvc比较许多不同的JS MV *框架

TODO mvc comparing many different JS MV* Frameworks

以上链接比较了所有JS mv *框架。这个演示应该特别感兴趣,

The above link compares all the JS mv* frameworks. This demo should particularly interest you,

Vanilla JS Todo mv *实施

Vanilla JS Todo mv* implementation

source

source

从它的声音中你明白了什么MVC对于如何在JS中实现它感到困惑,只需看看那里的许多不同的框架( ember.js backbone.js 等)及其来源以获取它们。待办事项清单是一个很好的起点。

From the sounds of it you understand what MVC is and are just confused as to how to implement it in JS, just look at the many different frameworks out there (ember.js, backbone.js, etc) and their source to get their take on it. The todo list is a great starting point.

这篇关于Vanilla JavaScript中的MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆