主干设计 [英] Backbone Design

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

问题描述

我刚刚开始使用 Backbone.我浏览了前两个 PeepCode 截屏视频,它们很棒,现在我正在研究未来应用程序的快速分离(无服务器端)模型.

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.

这就是我想要构建的(大致).一系列五个文本框 - 让我们称之为小部件.选择每个 Widget 输入后,将显示一个窗格,其中显示与 Widget 关联的任务,并允许用户创建新任务或销毁现有任务.

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.此外,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.

谢谢!

推荐答案

绝对让它成为事件驱动的.另外,尽量不要创建紧密耦合的视图.松散耦合将使您的代码更易于维护和灵活.

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:

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天全站免登陆