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?
# application.js
App.PostsView = SC.CollectionView.extend
templateName: 'post'
App.Post = SC.Object.extend
title: null
text: null
App.postsController = SC.ArrayProxy.create
content: []
addPost: (title, text) ->
post = App.Post.create title: title, text: text
@postObject host
# index.html
%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 contentBinding='??'}}