News for hackers. Stuff that matters.
Re:Backbone.js views done right by jashkenas on Thursday June 14, 2012 @12:48PM (#4112243)
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
Re:Backbone.js views done right by masklinn on Thursday June 14, 2012 @01:08PM (#4112359)
> 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.

Re:Backbone.js views done right by superchris on Thursday June 14, 2012 @01:55PM (#4112631)
I 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.
Re:Backbone.js views done right by ryanisinallofus on Thursday June 14, 2012 @01:02PM (#4112329)
"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.

Re:Backbone.js views done right by jashkenas on Thursday June 14, 2012 @01:24PM (#4112448)
Aw, I'm just horsing around. You're quite right that it's dangerous to mix metaphors while showing someone the ropes.
Re:Backbone.js views done right by ryanisinallofus on Monday June 18, 2012 @11:54PM (#4130170)
Lol. 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_Sec...
Re:Backbone.js views done right by dchuk on Thursday June 14, 2012 @03:58PM (#4113245)
I see what you did there
Re:Backbone.js views done right by jcromartie on Thursday June 14, 2012 @01:04PM (#4112336)
See: "rocket surgeon", or "enough rope to shoot yourself in the foot".

Also: jashkenas wrote Backbone.

Re:Backbone.js views done right by moron on Thursday June 14, 2012 @02:38PM (#4112842)
Seriously?! My fellow nerds drive me insane sometimes with their ridiculous focus on details that mean absolutely nothing. Arrrrrgh.
Re:Backbone.js views done right by mark_story on Thursday June 14, 2012 @09:05PM (#4114431)
I always assume people nitpicking pointless details have nothing better to say, but still want to say something. Plus, look how smart he/she looked.