我试图设置一个自定义属性,以后可以访问/编辑它。我什至在较旧的版本中可以使用fnSettings,但在1.10.5中如何使用它呢?
$('#table').DataTable({
customProp: 'Hello World'
});
然后单击按钮,我想我可以执行以下操作:
$('.test').on('click', function(e){
var table = $('#table').DataTable();
console.log(table.settings.oInit.customProp);
}
但是我得到:未捕获的TypeError:无法读取未定义的属性'customProp'
有人知道我该怎么做吗?
您可以使用jQuerydata()
方法将数据存储在关联的元素中。例如:
$('#table').data('customProp', 'Hello World');
稍后您可以检索它,如下所示:
$('.test').on('click', function(e){
console.log($('#table').data('customProp'));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句