JavaScript中的mvc是什么

发布于 2024-12-18 04:37:31 字数 345 浏览 1 评论 0原文

我多次听说过javascript中的mvc,但是我不知道mvc在js中是如何工作的。

由于我使用了goolge map v3,并且我找到了 MVCObject

看起来这是一个辅助类,用于注册和侦听对象的属性更改事件。

我认为这应该是“模型”,但是我还没有在那里找到“MVCView”。

我真的很困惑。

任何人都可以给我更多详细信息吗?

I heard of mvc in javascript many times,however I have no idea about how the mvc work in js.

Since I have used the goolge map v3,and I found the MVCObject.

It seems that this is a helper class used for register and listener the property chang event of the object.

I thinks this should be the "Model", Howver I have not found the "MVCView" there.

I am really confused with that.

Anyone can give me more details?

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

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

发布评论

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

评论(2

叹倦 2024-12-25 04:37:31

在 javascript 中,视图主要是由 js 中的某些视图类呈现的一些 html 模板。模型是一个绑定到该视图的类,以便在渲染时,来自该模型的数据被加载到模板中的正确位置。例如,看看 backbone.js

In javascript the view is mostly some html template that is rendered by some view class in js. The model is a class that is bound to that view so that, when it renders, the data from that model is being loaded on the correct positions in the templates. Take a look at backbone.js for example.

书间行客 2024-12-25 04:37:31

以下是 MVC 模式如何工作的高级简要概述:

控制器:

  1. 监听某种交互/事件流。
  2. 控制器可以向模型发送该类型的交互/事件。
  3. 控制器还可以与视图进行通信。

模型:

  1. 模型将监听来自控制器的交互/事件。
  2. 是数据源的抽象。
  3. 处理数据逻辑和操作。
  4. 完成逻辑后,它会发送到控制器,然后控制器将与视图进行通信。

视图:

  1. 视图可以与控制器进行通信。
  2. 知道如何将数据从模型直观地呈现到浏览器。
  3. 控制器告诉视图使用来自
    模型。

需要注意的几件事是模型不能直接与视图通信,反之亦然。只有控制器可以与视图和模型通信,因此控制器充当从浏览器上的用户交互中检索的交互/事件的委托者。

Here's a brief overview at a high level on how the MVC Pattern works:

Controller:

  1. Listens on some kind of interaction/event stream.
  2. Controller can send the model that type of interaction/event.
  3. Controller can also communicate with the the view.

Model:

  1. Models will listen in on the interaction/event from the controller.
  2. Is an abstraction of a data source.
  3. Handles data logic and manipulation.
  4. After it is done with logic, it then sends to controller which will then communicate with the view.

View:

  1. View can communicate with the controller.
  2. Knows how to render data from the Model to the browser visually.
  3. The Controller tells to View to do something with something from the
    Model.

A couple of things to note is that models can't communicate with views directly and vise versa. Only the controller can communicate with the view and model, so the controller acts as the delegator for the interaction/event retrieved from users interaction on the browser.

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