我想覆盖 Primefaces 数据表组件的函数。根据这个问题:如何在基于 widgetVar 的 Primefaces 组件中查找和/或覆盖 JavaScript? https://stackoverflow.com/questions/27551493/how-do-i-find-and-or-override-javascript-in-primefaces-component-based-on-widget可以通过使用PrimeFaces.widget.DataTable.prototype.
。但我只想为一个数据表覆盖此函数,而不是为所有数据表覆盖此函数。
这不起作用:
<p:dataTable widgetVar="myTable" ...>
</p:dataTable>
....
<script type="text/javascript">
$(document).ready(function(){
if (PF('myTable') !== undefined) {
PF('myTable').jq.datatable({
showCellEditor: function (c) {
console.log('my function');
}
});
}
});
</script>
这是应该这样做的还是我完全错了?
用我的一张桌子进行了测试:
PF('myTable').showCellEditor = function() {
console.log('my function')
}
如果需要,请不要忘记调用通用实现:
PF('myTable').showCellEditor = function() {
console.log('my function')
// call the generic implementation:
PrimeFaces.widget.DataTable.prototype.showCellEditor.call(this);
}
也可以看看:
- 使用 JavaScript 原型调用方法 https://stackoverflow.com/questions/560829/calling-base-method-using-javascript-prototype
- Primefaces widgetvar 简介 http://blog.hatemalimam.com/intro-to-primefaces-widgetvar/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)