【发布时间】:2012-06-14 14:53:33
【问题描述】:
我有以下设计
function crudDataTable()
{
this.addEditFormContainerSelector = '';
this.paginationType = "full_numbers"; // Provide Pagination Type
this.processing = true;
this.serverSide = true; //I want this this to be accessible in fnRowCallback below:
this.create = function(){
this.tableInstance = $(this.tableLocationSelector).DataTable({
"sPaginationType": this.paginationType
fnRowCallback:function(nRow, aData) {
// "this" from crudDataTable should be accessible here
}
})
}
}
我希望 crudDataTable 中的 this 可以在 fnRowCallback 中访问。
我怎样才能做到这一点?fnRowCallback 也是由datatable 组件触发的,所以这不在我的控制范围内。如何使 this 在 fnRowCallback 下可访问。
或者如果这是不可能的,那么还有什么其他方法可以实现它?
我正在尝试编写一个组件,这些组件的用户可以简单地设置其变量并调用 create 函数。我正面临在fnRowCallback 函数中访问this 的挑战。
谢谢。
【问题讨论】:
标签: javascript callback scope