主干网设计方案 [英] Backbone Design

查看:170
本文介绍了主干网设计方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始接触骨干。我经历了前两个窥视code截屏这是伟大的,去我现在在挖一个快速超脱(无服务器端)未来应用的实体模型。

I'm just getting started with Backbone. I went through the first two PeepCode screencasts which were great and now I'm digging in on a quick detached (no server side) mock-up of a future app.

下面就是我希望建立(大约)。一系列的五个文本框 - 允许调用这些小部件。每个插件的输入,选中时,会显示一个面板,以显示与小部件关联的任务,并允许用户创建一个新的任务或破坏现有的任务。

Here's what I'm looking to build (roughly). A series of five text boxes - lets call these Widgets. Each Widget input, when selected, will display a pane that shows Tasks associated with the Widget and allow the user to create a new Task or destroy existing Tasks.

在这一点上,我想我有以下型号:

At this point, I'm thinking I have the following models:

Widget
Task

以下集合:

Tasks
Widgets

下面的意见(这是它得到毛茸茸的!)

The following views (this is where it gets hairy!)

WidgetListView
  - Presents a collection of Widgets
WidgetView 
  - sub-view of WidgetListView to render a specific Widget
TaskPaneView 
  - Presented when the user selects a Widget input
TaskCreateView 
  - Ability to create a new Task associated with selected Widget
TaskListView 
  - Presents a collection of Tasks for the given widget
TaskView 
  - Displays Task detail - sub-view of TaskListView

假设是合理的,关键就变成了如何选择一个WidgetView时显示TaskPaneView。和futhermore,怎么说TaskPaneView应该反过来使TaskCreateViews和TaskListViews。

Assuming that's reasonable, the trick becomes how to display a TaskPaneView when a WidgetView is selected. And futhermore, how that TaskPaneView should in turn render TaskCreateViews and TaskListViews.

在这里真正的问题是:做一件级联呈现跨浏览事件?是否允许为根,以了解子视图,并明确使它们?如果这是事件驱动的?

The real question here is: Does one cascade render events across Views? Is it permissible for a Root view to know of sub-views and render them explicitly? Should this be event-driven?

道歉,如果这是一个开放式的问题,只是希望有人会看到以前类似的东西,并能指出我在正确的方向。

Apologies if this is an open-ended question, just hoping someone will have seen something similar before and be able to point me in the right direction.

谢谢!

推荐答案

绝对让事件驱动的。此外,尽量不要创建紧密耦合的看法。松散耦合会让你的code更容易维护,以及灵活的。

Definitely make it event driven. Also, try not to create views that are closely coupled. Loose coupling will make your code more maintainable as well as flexible.

看看这个职位上的事件聚合模式和骨干:

Check out this post on the event aggregator model and backbone:

<一个href=\"http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/\">http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/

短的版本是,你可以这样做:

The short version is you can do this:

var vent = _.extend({}, Backbone.Events);

和使用vent.trigger和vent.bind来控制您的应用程序。

and use vent.trigger and vent.bind to control your app.

这篇关于主干网设计方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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