-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If using subviews
hash, do we need registerSubview
or renderSubview
?
#94
Comments
Yes, the views in the subviews has get auto-registered, so you do not need to later call renderSubview. renderSubview is for manually rendering another subview later, after initialization. |
As far as the last question, I think they get named according to their key in the subviews hash. I'd have to test this, and you may be in a better position to verify this if you have code you're using right now. |
Alright, so if I understand correctly: I don’t need
|
(Oops—just noticed your second reply. I’ll see what I can do, but FYI I’m not super confident in my abilities here.) |
(I know people have strong opinions about CoffeeScript. If you happen to hate it, please stay your judgement upon me for now. Thanks!) Okay. So here’s a snippet of my code: SemestersFormView = View.extend({
autoRender: true
template: TEMPLATES.SemestersFormView
events:
'click [data-hook=add]': -> @collection.add new Semester()
subviews:
unassigned:
hook: 'unassigned-courses-container'
prepareView: (el) ->
return new COURSEVIEWS.CoursesListView(
collection: @_updateCourses(),
parent: @,
dragDropController: @dragDropController,
viewOptions:
filter: (c) -> c.taken is false
)
# ... rest of the class definition
}) Then, I can refer to the subview using
|
Yes the name collision problem is there, perhaps a discussion issue is in order since that exists for a lot of other things, including reserved words. |
@wraithgar Glad to hear it. I look forward to the discussion! |
To avoid naming collisions, I am using ...View as a suffix for subviews as a convention. So it is unassignedView, which is then accessible as view.unassignedView.collection.whatever. |
Yeah, that could work. But I would still prefer to access all subviews through an attribute, if it is possible to do this in a future release. In the meantime, if naming conventions are the official route that AmpersandJS is going on this issue, then it should probably be documented in the View conventions. |
#96 is related - throwing an error is a gold improvement. |
The subviews documentation is pretty thin compared to most of Ampersand. I’m interesting in using the
subviews
hash to write my subviews declaratively, but I’m having trouble getting it to work.subviews
hash get auto-registered?render()
, do I callthis.renderSubview
?subview.collection.on('add', function() {…})
? (In other words, if I want to attach the listener inside the parent view’sinitialize
, how do I refer to the subview I want from the hash?)The text was updated successfully, but these errors were encountered: