[英]How do I continue do things after finish footable initialize?
我使用名为 fooTable 的查询插件作为我的数据表( http://fooplugins.github.io/FooTable/ )
下面是我的代码来初始化我的数据表...
jQuery(function($){
$('.table').footable({
"paging": { "size": 15 },
// "toggleColumn": "last",
"showToggle": false,
"columns": $.get('/footable/js/columns.json'),
"rows": $.get('/footable/js/rows.json')
})
})
我的问题是完成初始化后如何做一些事情?
我试试
jQuery(function($){
$('.table').footable({
"paging": { "size": 15 },
// "toggleColumn": "last",
"showToggle": false,
"columns": $.get('/footable/js/columns.json'),
"rows": $.get('/footable/js/rows.json')
})
.done(function(){
alert('do something');
})
})
但它不起作用。
您应该使用postinit.ft.table
事件以及 @Roamer-1888 提到的on
选项。 (您可以单击任何选项以查看如何使用它的小示例。)
jQuery(function($) {
$('.table').footable({
// your other options
'on': {
'postinit.ft.table': function(e, ft) {
/*
* e: The jQuery.Event object for the event.
* ft: The instance of the plugin raising the event.
*/
// all initialized - do stuff here
}
}
});
});
或者,插件构造函数的第二个参数是一个就绪回调,因此您可以提供一个函数,以便在一切完成后执行。
jQuery(function($) {
$('.table').footable({
// your options
}, function(ft){
/*
* ft: The instance of the plugin raising the event.
*/
// all initialized - do stuff
});
});
使用postinit.ft.table
事件。 见http://fooplugins.github.io/FooTable/docs/jsdocs/FooTable.html#.event:Table%2522postinit.ft.table%2522
postinit.ft.table 事件在初始化任何组件之后但在第一次绘制表格之前引发。 在此事件上调用 preventDefault 将禁用表格的初始绘制。
此外, postdraw.ft.table
是您可能想要的。
我对它不是很熟悉。 所以试一试吧。 如果它不起作用告诉我。
.when('postinit.ft.table', function(e, ft){
//ok
})
FooTable 文档很难理解,因为它没有过多的例子。
我认为@turle 建议使用“postinit.ft.table”事件是一个很好的建议,但是我看不到.when('postinit.ft.table', function(e, ft){ /* do something */ })
是正确的语法。
据我可以从聚集在这里,事件处理程序使用的是“上”选项连接。
尝试:
jQuery(function($) {
$('.table').footable({
'paging': { 'size': 15 },
// "toggleColumn': "last",
'showToggle': false,
'columns': $.get('/footable/js/columns.json'),
'rows': $.get('/footable/js/rows.json'),
'on': {
'postinit.ft.table': function(e, ft) {
/*
* e: The jQuery.Event object for the event.
* ft: The instance of the plugin raising the event.
*/
// all initialized - do stuff here
}
}
});
});
试试'ready.ft.table'
类似的东西
jQuery(function($){
$('.table').footable({
"on": {
"ready.ft.table": function(e, ft){
// bind to the plugin initialize event to do something
}
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.