Backbone.js的主详细情况 [英] Backbone.js Master-Detail scenario

查看:104
本文介绍了Backbone.js的主详细情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Backbone.js的实施很经典的主从场景。

I have a classic master-detail scenario that I am implementing in backbone.js.

有关的那一刻,我不关心Backbone.js的,所以我跳过它的历史和导航部分。

For the moment I am not concerned with the history and navigation part of backbone.js so I am skipping it.


  • 我有一个GridView,所有的模型提取并从其他服务中显示。

  • 我有一个在这里从网格特定选择的模型显示有出现多个字段的DetailView(模态窗口),在主网格视图。

我已经实现:


  • ,所有骨干的意见和路由器连接一个主应用程序。

  • 应用程序初始化上
  • 文件下载
  • 主要骨干路由器(演技更是一个经典的控制器)与职责:

    • 创建和销毁的意见

    • 获取和发布数据

    • 将数据传递到的意见

    • 协调意见的活动

    现在从为GridView(骨干集合),其余服务返回的数据仅是模型的某些部分数据。

    Now the data returned from the rest service for the gridView (Backbone collection) is only some partial data of the models.

    因此​​,为了显示特定模型的完整细节我不得不从其他地区服务再次读取该信息。

    So to display the full details of a particular model I have to fetch the details again from the rest service.

    从模型抓取结束了从集合并在其上的任何更新断开的模型没有反映在集合本身,我必须再次刷新获取所有数据的主视图。

    Fetching from the model end up with a model disconnected from the collection and any update on it isn't reflected on the collection itself and I have to refresh again the master view fetching all the data.

    销毁并重新创建详细视图有时使其松散的查看事件。

    Destroying and recreating the details view sometimes make it loose the view events.

    什么是正确执行此方案的?
    我不完全理解的骨干做事的最佳方式。

    What would be the correct implementation of this scenario? I am not fully understanding the best way of doing things in backbone.

    推荐答案

    首先,我会建议为你的GridView的集合查询模型返回的全部细节。这解决了断开连接集合的问题。

    First, I would suggest returning the full detail for the models in your "gridView" collection query. This solves the 'disconnected collection' issue.

    虽然,你没有做充分收集负载 - 比方说做整个收集满负荷不会工作 - 细节过于巨大,例如,你应该能够通过相同从收集到的细节视图模型,测试,看看它的部分负荷或满负荷,并出具了取()为模型,返回完整的数据 - 是,这是同一型号的集合,应当更新。这是否有意义?

    Although, you don't have to do the full collection load - let's say doing a full load for the entire collection is not going to work - the details are too huge, for instance, you should be able to pass the same model from the collection into your detail view, test to see if its a partial load or a full load, and issue a "fetch()" for the model, returning the full data - being that this is the same model as in the collection, it should be updated. Does that make sense?

    另外,对于细节的意见,我会建议,特别是如果你只设计要求一个细节视图活跃,重用视图和写入,可以让你换出模型视图的功能。

    Also, for the detail views, I would suggest, especially if you're design only calls for one detail view active, to reuse the view and write a function in the view that allows you to swap out the model.

    因此​​,简言之:


    • 在应用程序启动,装入一张GridView控件和一个的DetailView。

    • 重构的DetailView允许模型进行设置就可以了。 (detailView.setModel(..)

    • 当用户希望看到一个模型的细节,使用上述函数传递模式进入的DetailView。

    • 如果模型没有完全加载,你则setModel方法可以去取()中的数据的其余部分。你可以为特定属性或者测试只会在那里满负荷,或在模型上设置属性,以表明其是否已经满载。

    • 如果你发现自己丢失的事件,试图在渲染()函数,它重新绑定事件结束调用delegateEvents()。

    • 由于相同的模型GridView的收集和的DetailView无论是在被使用,假设你应对变化的事件得当,一切都应该是同步的。

    这篇关于Backbone.js的主详细情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆