如何管理复杂的模型?或者只是缓存数据库中的数据?

发布于 2024-09-28 11:47:41 字数 387 浏览 0 评论 0原文

我的应用程序有作为组件的窗口。就我而言,现在我有 2 个组件,它们有一个下拉列表,显示当前登录的用户列表。因此,当我第一次使用一个组件时,它会向数据库发出请求,将数据保存在模型中,然后从模型中加载数据,但是当第二个组件打开时,它只会从模型中加载数据。现在很简单: ListModel:包含当前用户列表。

现在我有另一个组件,但这需要另一个用户的列表。我在哪里保存这些列表?我无法放入 ListModel,因为这样会与当前用户混淆。

提醒一下:不只有 2 个用户。它可能有更多的用户,所以它应该是可扩展的。

然后另一个问题可以解决这两个问题: 每个列表都有项目。它们会保存在ListItemModel中吗? 如何使列表之间不混合。那么 ListX 中的项目不会与 ListY 中的项目混淆吗?

谢谢

My app has windows that are components. In my case, now I have 2 components that have a drop down list that show the current logged user lists. So when I use one component for the first time it make a request to database, save data in model, and load data from model, but when the second component opens, it will just load data from model. Easy for now:
ListModel: this contains the current user lists.

Now I have another component but this needs the lists of another user. Where do I save these lists? I can't put in the ListModel as then will mix up with current user.

Just a remind: there is not just 2 users. It might have more users, so it should be scalable.

Then another problem that will solve both:
Each list has items. They will be saved in ListItemModel?
How to make to not mix between lists. So items from ListX doens't mix up with items from ListY?

thanks

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

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

发布评论

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

评论(1

给我一枪 2024-10-05 11:47:41

不要对模型胆怯。使用尽可能多的数据对数据进行建模以实现有效使用。您可以通过多种不同的方式对相同的数据进行建模。如果您发现模型之间存在共性,请提取一个基类供它们使用

Don't be timid with the models. Use as many as you need to model your data for effective use. You can model the same data in several different ways. If you find commonality between models, extract a base class for them to use

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