加载后的骨干js事件

时间:2013-03-07 15:11:12

标签: jquery backbone.js

我有一个div:

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

此div位于骨干视图加载的模板中。

这是Backbone视图:       DetailsView = Backbone.View.extend({         事件:{.....});

我想在模板加载时调用以下jquery函数:

我该怎么做?

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

来自扩展程序jquery插件。

3 个答案:

答案 0 :(得分:5)

你可以做点什么:

... 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 :(得分:1)

可以这样做:

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

答案 2 :(得分:0)

您是否已将JS文件包含在标题中?或在页脚部分。这是实施过程中出现的一个常见问题。

相关问题