2
votes

I have a div:

<div class = "desc"></div>

this div is in a template that a backbone view loads.

Here's the Backbone View: DetailsView = Backbone.View.extend({ events: {.....});

I want when the template loads, to call the following jquery function:

How can I do that?

 $('#desc').expander({
     slicePoint: 50,
     expandText: 'Click Here to Read More',
     userCollapseText: 'Hide Text'
 });

It is from the expander jquery plugin.

3
Show us the code for you Backbone view. - Lowkase
Use underscores _.defer() method in the render. - Joe

3 Answers

5
votes

you could do something like:

... Rest of View...

render: function() {
    // do your normal render stuff
    this.afterRender();
},

afterRender: function() {
    // do the stuff you want to do after the template is rendered
}
1
votes

It is possible to do something like that:

initialize: function () {
    this.once('renderEvent', function () {
        // that will be executed just once after the view has been rendered
    });
},

render: function () {
    // display html
    // ...
    this.trigger('renderEvent');
}
0
votes

have you included your JS files in the header ? or in footer section. This is one common issue happens during implementation .