从Primefaces特定小部件覆盖方法 [英] Override a method from a Primefaces specific widget
本文介绍了从Primefaces特定小部件覆盖方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想覆盖Primefaces数据表组件的功能。根据这个问题:如何在Primefaces组件中找到和/或覆盖基于widgetVar的JavaScript?可以使用 PrimeFaces.widget.DataTable.prototype。
。但我想只为一个数据表覆盖此函数,而不是全部。
I want to overwrite a function of Primefaces datatable component. According to this question: How do I find and/or override JavaScript in Primefaces component based on widgetVar? it is possible by using PrimeFaces.widget.DataTable.prototype.
. But I want to override this function for one datatable only, not for all.
这不起作用:
<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>
这是应该怎么做的,还是我完全错了?
Is this how it is supposed to be done or am I completely wrong?
推荐答案
使用我的一张表进行测试:
Tested with one of my tables:
PF('myTable').showCellEditor = function() {
console.log('my function')
}
如果需要,请不要忘记调用通用实现:
Don't forget to call the generic implementation if you need to:
PF('myTable').showCellEditor = function() {
console.log('my function')
// call the generic implementation:
PrimeFaces.widget.DataTable.prototype.showCellEditor.call(this);
}
另见:
- Calling method using JavaScript prototype
- Intro to Primefaces widgetvar
这篇关于从Primefaces特定小部件覆盖方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文