zepto - Correct way to insert a view with Backbone.js -


i have simple backbone.js app. want render view dom of html page, view detail view model. html page has div element want render view into. if try render view this:

detailview = new rulespanelview({model : @model}) $("#detail").html(detailview.render().el) 

it fails , [object htmldivelement] inserted dom, not rendered html.

this way can work , seems hack:

$("#detail").html('') detailview = new rulespanelview({model : @model}) $("#detail").append(detailview.render().el) 

having empty html of div before rendering don't multiple views rendered inside #detail happend append.

also aren't creating way many views way, seems cleaner replace html in first code segment?

what correct way render view?

what want pass inserted dom node view 'el' option constructor:

new rulespanelview({el: $("#detail")}); 

this way, won't render again. still need make sure view's 'render' method able render correct view updated model, though.

the backbone documentation mentions way avoid rendering stuff @ once.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -