5 ms·
Whoa there nellie. Complexity ahoy. Why would you want to have a view that dumps out its HTML as a string? If a string of HTML is all you want, don't use a vie
by jashkenas 14y ago
Whoa there nellie. Complexity ahoy.
Why would you want to have a view that dumps out its HTML as a string? If a string of HTML is all you want, don't use a view, just use a template.
But putting that aside for a second ... for this particular example, how about this:
render: ->
this.$el.html JST["table_view_template"]()
tbody = this.$el('tbody')
for person in this.collection.models
view = new TableRowView model: person
tbody.append view.render().el
... or if you were in earnest about only needing the raw HTML from the sub-view, how about just rendering the row templates within the table template, making your render function as simple as this:
render: ->
this.$el.html this.template people: this.collection
- ryanisinallofus 14y ago"Whoa there nellie. Complexity ahoy." Mixing metaphors? Is it a horse or a ship you are riding? It's really hard to read the rest of your technical reasoning (which makes sense) with opening statements like that.
- jcromartie 14y agoSee: "rocket surgeon", or "enough rope to shoot yourself in the foot". Also: jashkenas wrote Backbone.
- jashkenas 14y agoAw, I'm just horsing around. You're quite right that it's dangerous to mix metaphors while showing someone the ropes.
- dchuk 14y agoI see what you did there
- ryanisinallofus 14y agoLol. This is the kind of shit I'm talking about. In my head jashkenas looks just like this guy when he writes like this: http://upload.wikimedia.org/wikipedia/en/thumb/7/7c/Lulz_Security.svg/200px-Lulz_Security.svg.png http://upload.wikimedia.org/wikipedia/en/thumb/7/7c/Lulz_Sec...
- moron 14y agoSeriously?! My fellow nerds drive me insane sometimes with their ridiculous focus on details that mean absolutely nothing. Arrrrrgh.
- mark_story 14y agoI always assume people nitpicking pointless details have nothing better to say, but still want to say something. Plus, look how smart he/she looked.
- masklinn 14y ago> or if you were in earnest about only needing the raw HTML from the sub-view, how about just rendering the row templates within the table template, making your render function as simple as this: And if you want to delegate the handling of these DOM lines to sub-views (for event handling), you can instantiate them after rendering and call `View#setElement` with a row each.
- superchris 14y agoI started with an approach like yours, but really wanted the ability to have a subview helper function that inserts the subview in the right place in the parent's template. In order for this to work, I need the helper function to output the subview's element but defer rendering the subview until the subview's element is in the DOM. One case I really feel I see benefit from this is in creating reusable subviews for form elements, but I wanted to choose a simpler example to show the approach. Could be the example I chose was too simple.