Backbone JS 模型到底可以用来做什么?这太远了吗?

发布于 2024-10-27 10:20:34 字数 571 浏览 4 评论 0原文

我有一个关于 Backbone JS 模型的问题。最近几天我已经深入研究了 Backbone JS。我现在明白了(感谢 Stackoverflow,我对一些事情有了进一步的了解)。

目前,我的网络应用程序正在使用骨干模型来存储动态导航和其他此类位。通常在骨干集合中使用的东西。目前,我的网络应用程序仍然需要存储某种“全局”状态......例如用户当前在导航中选择的内容(然后影响应用程序的其他部分等)

我一直保留所有这些存储在变量中的“状态”如下所示:

App.data.selectedPage = 等等。

但我更多地考虑的是骨干模型......我应该将这些“全局状态”存储在模型中吗?这是模型可以用来做的事情吗?

目前,Web 应用程序不会保存到服务器或本地存储,它更像是我必须为 iPad 编写的转换后的 Flash 演示文稿。因此,使用 Backbone 之类的东西来进行代码组织仍然是有意义的……我的意思是,这也可以,对吧?要使用 Backbone,即使我不打算将模型存储在任何地方?

无论如何,是的,使用模型来存储此类信息也可以吗?有什么事吗? ...请告诉我我的做法是否错误。

非常非常感谢。 詹姆斯

I have a question regarding Backbone JS's Models. I've already delved into Backbone JS quite a bit the last few days. I am understanding it now (and thanks to Stackoverflow, I have understood further with a few things).

At present, my web app is using Backbone Models to store dynamic navigation and other such bits. Stuff that is generally used in Backbone Collections. At present, my web app is still needing to store sort of 'global' states... Such as what the user has currently selected in the navigation (which then effects other parts of the app etc.)

I've been keeping all of these stored 'states' in variables like this:

App.data.selectedPage = whatever etc.

But I'm thinking more about Backbone Models... Should I be storing these 'global states' in a Model? Is that something that the Models can be used for?

At present, the webapp doesn't save to the server, or local storage, it's more of a converted Flash presentation I have to code for an iPad. So it still made sense to use something like Backbone for code organisation purposes... I mean, that's ok too right? To use Backbone, even I don't intend on storing the models anywhere?

Anyhow, yes, using models to store this sort of information is ok too? Anything goes? ...please do tell me if I'm approaching this wrong.

Many, many thanks.
James

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

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

发布评论

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

评论(1

用心笑 2024-11-03 10:20:34

我认为使用主干模型的一个好的经验法则是,当某些数据发生变化时,您是否需要事件。

例如,您有一个包含选定日期的日历。应用程序的许多其他部分(视图)需要了解并获悉所选日期。然后,将日期存储在模型中并让每个人收听日历中的事件就有意义了。

这更多的是与数据相关的功能。对于状态来说则不同。您选择的页面对我来说是一种状态。页面选择、页面状态、全局变量,它们应该在您的控制器中。他们(或它)应该知道页面的状态是什么,并且可以在页面更改时触发事件。

型号=>以事件为中心的数据

I think one good rule of thumb for using backbone model is if you need events when some data is changing.

For exemple, you have a calendar with a selected date. Many other parts (views) of your app needs to know and be informed about the selected date. Then it makes sense to store the date in a model and have everyone listen on events from the calendar.

This is more for data related functions. For state it is different. Your selected page is a state to me. Page selection, page state, globals, they should be in your controllers. They (or it) should know what the state of the page is and they can trigger event when it changes.

Model => data centric with events

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