简体   繁体   English

如何在Sproutcore中拆分视图文件?

[英]How to split a view file in Sproutcore?

Suppose you have a SC.SplitView to implement a master-detail functionality, right now I would like to have one developer to work on customizing the SC.ViewList of the master piece, while have another to work on customizing and usability of the SC.View of the detail. 假设您有一个SC.SplitView来实现主从功能,现在我想让一个开发人员来定制主件的SC.ViewList,而让另一个开发人员来进行SC的自定义和可用性。详细视图。

As the page is growing more and more I was wondering if there would be a known practice on how to split the file in two having the SC.View master-child in one file and the SC.View detail-child in another. 随着页面的增长,我想知道是否存在一种已知的做法,如何将文件分为两个,一个文件中包含SC.View主子对象,另一个文件中包含SC.View详细子对象。

Has anyone run into this need? 有没有人遇到这种需要?

You can easily split your views into multiple files and this is highly encouraged! 您可以轻松地将视图拆分为多个文件,强烈建议您这样做!

The main premise is that you will have three views: 主要前提是您将拥有三个视图:

  1. The SC.SplitView SC.SplitView
  2. The left view, and 左视图,以及
  3. The right view 正确的看法

You'll need to use sc_require so that the SplitView can find the others. 您将需要使用sc_require以便SplitView可以找到其他的。 Here's a quick example: 这是一个简单的示例:

# Inside my_app/resources/main_page.js

sc_require('views/left_split_panel')
sc_require('views/right_split_panel')

SplitView.extend({
  childViews: ['leftPanel', 'rightPanel'],

  leftPanel: MyApp.LeftSplitPanelView.extend(SC.SplitChild, {
    minimumSize: 200
  }),

  rightPanel: MyApp.RightSplitPanelView.extend(SC.SplitChild, {
    autoResizeStyle: SC.RESIZE_AUTOMATIC
  })
})

Then, the other two views: 然后,另外两个视图:

#inside my_app/views/left_split_panel.js

MyApp.LeftSplitPanelView = SC.View.extend({
  childViews: ['someView anotherView'],

  someView: SC.View.extend(...),
  anotherView: SC.View.extend(...)
})

and

#inside my_app/views/right_split_panel.js

MyApp.RightSplitPanelView = SC.View.extend({
  childViews: ['dudeView sweetView'],

  dudeView: SC.View.extend(...),
  sweetView: SC.View.extend(...)
})

Checkout the "Separating Views" section of the second Getting Started guide for more info and perhaps a better example (quick note: SC.View.design() and SC.View.extend() are almost identical, but .design() has been deprecated; we're in the process of updating the guides to match best practices). 请查看第二本《 入门指南 》的“分离视图”部分,以获取更多信息和更好的示例(快速注意: SC.View.design()SC.View.extend()几乎相同,但是.design()具有已过时;我们正在更新指南以匹配最佳做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM