重新初始化JQuery具有XPages部分刷新更新DOM [英] Re-Initialize JQuery have XPages Partial Refresh updates DOM

查看:78
本文介绍了重新初始化JQuery具有XPages部分刷新更新DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自核心控件的选项卡式面板,并且在内部是一个<xp:inputText>,其中有一个用于限制字段长度的jQuery的钩子.当我将页面更改为编辑模式时,如果在屏幕上显示此选项卡,效果很好.但是,如果我不在该选项卡上并切换到编辑模式,然后更改为所需的选项卡,则它将不起作用.

I have a tabbed panel from the core controls and inside it is an <xp:inputText> which has a hook for some jQuery used to limit the field length. It works great if I have this tab on the screen when I change the page to edit mode. If however I am not on that tab and switch to edit mode and THEN change to the tab I want, it does not work.

我认为这是因为jQuery启动时这些控件不存在.任何人都知道让jQuery刷新以获取初始加载时不存在的新DOM添加的方法吗?

I assume it's because these controls did not exist when jQuery fired up. Anyone know a way to have jQuery refresh itself to pick up the new DOM additions that weren't there on initial load?

这是页面上方的代码:

<xp:scriptBlock id="scriptBlock1">
        <xp:this.value><![CDATA[$('input[maxlength]').maxlength({
            alwaysShow: true,
            threshold: 10,
            warningClass: "label label-success",
            limitReachedClass: "label label-danger"
        });]]></xp:this.value>
    </xp:scriptBlock>

字段为:

<xp:inputText id="inputText2"
                        value="#{viewScope.vsWorkingContentAdd.description}">
                        <xp:this.attrs>
                            <xp:attr name="maxlength" loaded="true" value="75"></xp:attr>
                        </xp:this.attrs>
                    </xp:inputText>

同样,该代码可以正常工作,因为它可以找到已经存在的字段.当您进行部分刷新并出现<xp:inputText>时,此问题与XPages有关,如何让jQuery看到它?

Again, the code works, as it finds fields that already exists. This question is about in XPages when you do a partial refresh and an <xp:inputText> appears, how do you get jQuery to see it?

推荐答案

您正确的是,具有部分属性和事件通过javascript分配的对象的对象将在部分刷新期间重新加载后需要重新分配.您可以将脚本块修改为如下所示:

You are correct that objects which have attributes and events assigned through javascript will need them re-assigned after they are reloaded during a partial refresh. You can modify the script block to look something like this:

function setValidation() {
    $('input[maxlength]').maxlength({
        alwaysShow: true,
        threshold: 10,
        warningClass: "label label-success",
        limitReachedClass: "label label-danger"
    });
 }

$(document).ready(function() {
    setValidation(); // On page load
    dojo.subscribe('partialrefresh-complete', function(method, form, refreshId, options) {
        setValidation(); // On partial refresh
    });
});

这篇关于重新初始化JQuery具有XPages部分刷新更新DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆