jewelwast
jewelwast

Reputation: 2777

Backbone js event after load

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.

Upvotes: 2

Views: 8788

Answers (3)

user1452840
user1452840

Reputation: 221

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

Upvotes: 0

snedkov
snedkov

Reputation: 309

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');
}

Upvotes: 1

Andbdrew
Andbdrew

Reputation: 11895

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
}

Upvotes: 6

Related Questions