2013-03-07 266 views
2

后,我有一个div:骨干JS事件负载

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

这个div是在骨干视图加载的模板。

这里是骨干视图: DetailsView = Backbone.View.extend({{} {{}};

我希望在模板负荷,调用下面的jQuery函数:

我怎么能这样做?

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

它来自扩展器jquery插件。

+0

向我们展示您的代码主干视图。 – Lowkase 2013-03-07 15:13:30

+0

在渲染中使用下划线_.defer()方法。 – Joe 2013-03-07 23:29:09

回答

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

这是可以做到这样的事情:

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

你纳入你的头JS文件?或在页脚部分。这是实施过程中发生的一个常见问题。