如果我有一个没有模型的主干视图,我是否会偏离 MVC?

发布于 2024-12-04 15:26:51 字数 124 浏览 3 评论 0原文

我有几个视图,它们似乎没有逻辑上连贯的模型。我仍然可以尝试为这些创建虚拟模型(并且也适当地具有路由器),但这对我来说似乎不自然。

那么,拥有一个没有相应模型的主干视图是一种反模式吗?

专家对此有何评论?

I have a couple of Views which do not seem to have logically coherent Models. I can still try to create dummy Models for these (and properly have routers as well) but it seems unnatural to me.

So is having a Backbone View without a corresponding Model an anti-pattern?

What do the experts say on this?

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

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

发布评论

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

评论(3

枫林﹌晚霞¤ 2024-12-11 15:26:51

主干的各个组成部分可以很好地配合,但它们没有必要总是在一起。

我经常有没有视图的模型,以及没有模型的视图。主干应用程序的每个部分都可以通过多种不同的方式使用,以方便您需要应用程序执行的操作。

the various components of backbone play well with each other, but there's no need for them to always go together.

i very regularly have models with no views, and views with no models. each of the pieces of a backbone app can be used in many different ways to facilitate what you need your app to do.

眼波传意 2024-12-11 15:26:51

我不认为这是一种特定的反模式。如果您想要做的只是封装视图行为,那么编写视图并将其附加到元素可能是有意义的。它可能没有任何业务逻辑或持久数据......它可能只是一个封装视图行为的视图(就像基于事件管理元素状态的东西)。在这种情况下,就不需要模型了。

另一方面,如果您正在管理一堆变量(无论是否持久)和任何类型的业务逻辑,那么将其分解为模型是有意义的。

I don't think it is specifically an anti-pattern. If all you are trying to do is encapsulate view behavior, it might make sense to write a view and attach it to an element. It might not have any business logic or persistable data... it might just be a View that encapsulates view behavior (like something that manages the state of an element based on events). In that case, there is no need for a model.

On the other hand, if you are managing a bunch of variables (persistable or not) and any type of business logic, then it makes sense to break that out into a model.

流星番茄 2024-12-11 15:26:51

如果您正在考虑添加虚拟模型或任何其他逻辑/代码以使架构适合某种模式,那么这应该是一个转移注意力的事情。该模式应该可以帮助您设计逻辑上组织良好的可预测代码。

If you are considering adding a dummy model or any other logic/code to make the architecture fit a pattern, that should be a red herring. The pattern should be there to assist you in designing logically well organized predictable code.

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