轮询页面后,Javascript停止运行

时间:2018-05-08 18:13:17

标签: javascript primefaces

我正在使用primefaces创建一个网页,我有一个嵌入的脚本,以便我可以切换行。在页面中,我还有一个轮询来更新页面的内容。首次加载页面时,脚本运行完美,但是一旦页面轮询自己更新内容,脚本就会停止工作。

该脚本来自另一个stackoverflow帖子,我没有javascript经验,所以我不确定是什么部分导致了这个问题。

<script type="text/javascript">
    $(document).ready(function() {
        rowExpansion(PF('dtbl'));
    });

    function rowExpansion(dataTable) {
        //dataTable should be the widgetVar object
        var $this = dataTable;
        //add the 'hand' when hovering on row
        $this.tbody.children('tr').css('cursor', 'pointer')
        $this.tbody.off('click.datatable-expansion', '> tr')
        .on('click.datatable-expansion', '> tr', null, function() {
            //toggle the current row the old toggler
            $this.toggleExpansion($(this).find('div.ui-row-toggler'));
        });
    }
</script>

1 个答案:

答案 0 :(得分:0)

根据@Kukeltje和@AdamS提供的建议,我通过调查我的poll对象中oncomplete脚本中的函数来修复此问题。该脚本仅在页面初始化时被调用,并且每当触发轮询时都需要调用该脚本。以前是......

<p:poll interval="30" listener="#{dashboardBean.update}" update="reporttbl" oncomplete="rowExpansion(PF('dtbl'))" />

现在......

<link rel="stylesheet" type="text/css" href="style.css">
相关问题