Backbone js event after load
我有一个div:
1 |
此div位于主视图加载的模板中。
这是主干网视图:
DetailsView = Backbone.View.extend({
事件:{.....});
我希望在模板加载时调用以下jquery函数:
我该怎么做?
1 2 3 4 5 | $('#desc').expander({ slicePoint: 50, expandText: 'Click Here to Read More', userCollapseText: 'Hide Text' }); |
来自扩展器jquery插件。
您可以执行以下操作:
1 2 3 4 5 6 7 8 9 10 | ... 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 2 3 4 5 6 7 8 9 10 11 | 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'); } |
您是否已将标头中包含JS文件?或在页脚部分。这是在实施过程中发生的一个常见问题。