3

I'm using BBB with the great LayoutManager for the views. Unfortunately, i can't find a way to re-render specific subviews. Here is my setting:

Home.Views.Layout = Backbone.Layout.extend({
    template: "home/home",
    el: "#main",
    views: {
        "#left-menu-container": new Home.Views.Leftmenu(),
        "#searchbox": new Home.Views.Searchbox(),
        "#content": new Home.Views.Content()
    }
});

Home.HomeView = new Home.Views.Layout();
Home.HomeView.render();

Home.Views.AddEditPatient = Backbone.View.extend({
    template: "......",
    events: {
        'click .dosomething': 'dosomething'
    },
    dosomething: function(){
        // [dosomething]

        // Only Render Sub-View, e.g. #content here...
   }
});

I don't want to re-render the whole layout, what would be possible by calling Home.HomeView.render() again, but how can i render only the sub-view in this setting?

fabian_p
  • 107
  • 1
  • 7

3 Answers3

2

I think you want to add to do something like this with backbone.layoutmanager

thisLayout.setView("#content", new View()).render();

The backbone.layoutmanager v0.6.6 documentation might be helpful http://documentup.com/tbranyen/backbone.layoutmanager/#usage/nested-views

Also check http://vimeo.com/32765088

Gabo Esquivel
  • 3,494
  • 2
  • 23
  • 18
  • 3
    That should work. Tim, the contributer of LayoutManager pointed me to the best solution: Home.HomeView.getView("#content").render(); - sometimes life is so easy -,- – fabian_p Feb 14 '13 at 16:56
0

If I understand your question correctly, you can do this in your dosomething function:

this.$("#divToRenderTo").html(new subView().render().$el);

Be sure to have "return this;" at the end of your sub-view's render function.

Nords
  • 91
  • 1
  • 8
0

There are two ways I generally do this with layoutmanager:

  1. Instantiate views in your initialize function and then drop them into the view in beforeRender. This gives your view access to the subview so you can render it directly.

    initialize: function() {
        this.subview = new SubView();
    },
    beforeRender: function() {
        this.insertView(this.subview);
    },
    doSomething: function() {
        this.subview.render();
    }
    
  2. You can use view.getView(#selector) to return the embedded view and then call render on that.

    doSomething: function() {
        this.getView('#content').render();
    }