I'm trying to write a complicated app in SC2. There's no editing component yet, just a display of (lots of data). Starting from the Todos & Handlebars guides, here's some of the stuff I've had to google for, or wasn't readily obvious.
Note: I like coffeescript and haml
-
Why is there sometimes references to
SC.ArrayController
?- Colin C: it was gone but its back now. we need to generate the docs again.
-
Why is
App.fooController
anSC.Object
, andApp.foosController
anSC.ArrayProxy
? Shouldn't there just be a genericSC.Controller
, orSC.CollectionController
, if the behavior is different? -
How do I nest controllers? Eg,
BlogApp.postsController
andBlogApp.commentsController
, where I want to display several posts and their comments on the page?- How do I organize the view templates? What do I say in the post template where I want the comments to go?
- Looks like I put
{{view comments}}
in the post template? Or maybe{{#collection}}
? What goes in thecontentBinding
attribute in that case?
- Looks like I put
- How do I organize the view templates? What do I say in the post template where I want the comments to go?
-
If I follow the handlebars guide, and put
<script type="text/x-handlebars" ...>
in the<head>
, how do I specify where to put the rendered result? Eg, if I have a div#content, how do I tell SC I want the template rendered there? -
How do I hook up a SC.View to a SC.Object?
- Does
SC.CollectionView
replace the need for apostsController = SC.ArrayProxy.create
? If so, how? If not, how do I wire a collectionView and a controller together? itemViewClass: SC.View.extend(...)
kinda sucks. How aboutitemTemplateName: 'post'
?
- Does
-
Only double-quotes work inside {{collection foo="bar"}} attributes. Single quotes gives the unhelpful error:
Expecting 'STRING', 'INTEGER', 'BOOLEAN', 'ID'
.
App.Post = SC.Object.extend
title: null
text: null
App.Comment = SC.Object.extend
author: null
text: null
App.PostsView = SC.CollectionView.extend
itemViewClass: SC.View.extend(
templateName: 'post'
)
App.CommentsView = SC.CollectionView.extend
init: ->
@set('contentController', App.CommentsController.create(content: @get('content')))
contentBinding: 'contentController.content'
itemViewClass: SC.View.extend(templateName: 'comment')
App.postsController = SC.ArrayController.create
content: []
addPost: (title, text) ->
post = App.Post.create title: title, text: text
@pushObject post
App.CommentsController = SC.ArrayController.extend
addComment: (title, text) ->
comment = App.Comment.create author: author, text: text
@pushObject comment
$ ->
post = App.postsController.addPost "SproutCore 2.0", "lorum ipsum"
post.commentsController.addComment("Paul", "lorum ipsum")
%h1 My Blog
#posts
{{collection App.PostsView contentBinding="App.postsController"}}
%script{type: 'text/x-handlebars', 'data-template-name' => 'post'}
%article
%h2
{{content.title}}
{{content.text}}
.comments
{{collection App.CommentsView contentBinding="contentView.commentsController"}}
%script{type: 'text/x-handlebars', 'data-template-name' => 'comment'}
%h3
{{content.author}}
{{content.text}}