2014-01-08 62 views
0

我有一个自定义对话框必须显示在多个地方,我想尽量减少代码的乘法。如何将对象传递给jquery函数?

<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(event)。我已经试过这样的事情

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,使surveyPanel可以cancelOrderBalloonYesSurvey被关闭()?

+0

surveyPanel是什么?我没有看到带有该ID或类的标签。 – jalynn2

+0

它是第一行代码的一部分:widgetVar =“surveyPanel” – user1860447

回答

0

在这种情况下,我会通过参数为一个字符串:

cancelOrderBalloonYesSurvey(event, 'surveyPanel'); 

和使用PF功能如下消耗字符串:

PF('surveyPanel').close(); 

你也可以传递对象是这样的:

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