如何将对象传递给jquery函数?

时间:2014-01-08 19:08:39

标签: jquery primefaces

我有一个自定义对话框,必须在多个地方显示,我想最小化代码乘法。

<p:dialog id="basicDialog" dynamic="true" header="Test Page Survey" widgetVar="surveyPanel"
          showEffect="slide"  hideEffect="drop"  visible="false" modal="true" closable="false"
          onShow="somecondition()">
    <h:form id="surveyForm" styleClass="wizard-panel" enctype="multipart/form-data">
        ...
        ...

       <div id="saveCancelDiv" class="navigation-panel">
            <p:commandButton id="btnCancelSurvey"
                             value="Cancel"
                             onclick="someJS.cancelOrderBalloonShowSurvey(); return false;"
                             type="button"
                             styleClass="cancel-button"/>
            <p:commandButton id="btnContinue"
                             value="Continue"
                             style="float:right;"
                             oncomplete="someJS.handleDialogSubmit(xhr, status, args);"
                             actionListener="#{xx.save}"
                             styleClass="continue-button" />
        </div>

    </h:form>
</p:dialog>

<cp:confirmDialog id="cancel-order-confirm-dialog-survey" umb_key="cancel-order-confirm-dialog-survey" position="right bottom" modal="true" style="z-index: 2000;">

    <div id="outputPanel" class="alert-dialog" >
        Do you really want to cancel this order?
        <br/>

        <p:commandButton id="btnCancelOrderYes" value="Yes" onclick="someJS.cancelOrderBalloonYesSurvey(event); return false;" type="button" />
        <p:commandButton id="btnCancelOrderNo" value="No" onclick="someJS.cancelOrderBalloonHideSurvey(event); return false;"  type="button" />

    </div>
</cp:confirmDialog>

cancelOrderBalloonShowSurvey(),cancelOrderBalloonYesSurvey()和cancelOrderBalloonHideSurvey()是每次有人想要使用时应该使用的JS函数 自定义确认对话框。但事实并非如此。 我想要做的是将'surveyPanel'对话框传递给cancelOrderBalloonYesSurvey(事件)。我尝试过这样的事情

    cancelOrderBalloonYesSurvey(event, surveyPanel) -> this did not work
    cancelOrderBalloonYesSurvey(event, this.surveyPanel) -> this did not work
    cancelOrderBalloonYesSurvey(event, this.parent.surveyPanel) -> this did not work    

如何将指针传递给surveyPanel,以便可以在cancelOrderBalloonYesSurvey()中关闭surveyPanel?

1 个答案:

答案 0 :(得分:0)

在这种情况下,我会将参数作为字符串传递:

cancelOrderBalloonYesSurvey(event, 'surveyPanel');

使用PF函数消耗字符串,如下所示:

PF('surveyPanel').close();

你也可以这样传递对象:

cancelOrderBalloonYesSurvey(event, PF('surveyPanel'));