Search code examples
jquerybackbone.jsmarionettebackbone-views

inside a Backbone.Marionette view render function I have Method that requires height value?


The Question is where in the Marionette view are you suppose to put a jquery method that doesn't require an event to instante it.

inside the view I have

onRender: function(  ) {          
            this.$('.loan-tool-bar').sticky();
            this.$('.sticky-wrapper').height(64);
  },

The above is working fine for me;

the problem is I want to set the height of sticky-wrapper based on the height of the .loan-tool-bar

so I tried this

   this.$('.loan-tool-bar').sticky();
   this.$('.sticky-wrapper').height(this.$(".loan-tool-bar").outerHeight());

this is giving the value of 0 on the sticky-wrapper

if i console log $(".loan-tool-bar").outerHeight(); I get the value of 64

the problem is that the onRender is not getting the displayed value.

how can i solve this?


Solution

  • This is already resolved in comments, but still this is a good enough answer to post:

    The onRender is called after the view was rendered but it doesn't mean that the view is shown on screen in it's place and size. The solution is to setup size only after the view is shown by it's region/layout using the onShow fucntion.