我应该去做什么架构,这不是一个不好的架构

发布于 2025-01-17 12:37:56 字数 199 浏览 3 评论 0原文

我有一个大表单要显示,无法在单个页面上显示。所以我们所做的是将其分为 7 个部分,每个部分由 1 个片段组成,所有这些片段都使用选项卡布局和视图分页器进行导航。每个片段都有自己的视图模型,以便访问数据绑定。现在的问题是我们可以随机选择任何选项卡并更新数据,因此我们需要一个中心位置来存储该数据并更新它,但数据是复杂的 json 模型,因此无法轻松存储在数据库中,还有其他选择吗去追求?

I have a large form to show which can not be displayed on a single page. so what we did is divide it into 7 part, each part consist of 1 fragment and all those fragments are navigated using tab layouts and view pager. each of those fragments have their on view model in order to access data binding . Now the problem is we can randomly select any tab and update data so we need a central location to store that data and update it, but the data is complex json model so can't be stored in a database easily, is there any other option to pursue?

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

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

发布评论

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

评论(1

彻夜缠绵 2025-01-24 12:37:56

如果要集中数据,请使用活动示波器的ViewModel。

在下面的片段中初始化视图模型:

private val someViewModel: SomeViewModel by activityViewModels()

private val someOtherViewModel: SomeOtherViewModel by lazy {
        ViewModelProvider(requireActivity()).get(SomeOtherViewModel::class.java)
}

这样,您可以将所有数据操作或单个位置的完整组合成集中。

If you want to centralize the data then use Activity Scoped ViewModel.

Initialized your viewmodel in your fragments as below:

private val someViewModel: SomeViewModel by activityViewModels()

OR

private val someOtherViewModel: SomeOtherViewModel by lazy {
        ViewModelProvider(requireActivity()).get(SomeOtherViewModel::class.java)
}

This way you can centralize all your data manipulation or form completion at single place.

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