Sharepoint 2010模态对话框 - 在对话框中打开一个对话框

时间:2016-10-27 14:50:42

标签: javascript sharepoint

我正在使用SharePoint 2010,并且我已设法在模式对话框中打开列表。我现在尝试在单击按钮时在同一模式对话框中打开另一个列表。 (理想情况下,关闭第一个对话框,然后打开另一个) 这是我的模态对话框声明:

function OpenDialog(url)
    {
      var dialogOptions = SP.UI.$create_DialogOptions();
      dialogOptions.url = url // URL of the Page
      dialogOptions.title = 'Dialog Window'
      dialogOptions.allowMaximize= true
      dialogOptions.width = 635; // Width of the Dialog
      dialogOptions.height = 335; // Height of the Dialog
      SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
    }
    function DialogCallback(){
       SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,'Cancelled'); 
       }

所以我设法正确关闭了对话框,但我似乎无法打开它。我以www.google.co.uk为例,我只需要在同一个对话框中打开(替换当前的那些)或关闭当前对话框并重新打开一个新的...

href="#" onclick="window.frameElement.cancelPopUp(); OpenDialog(url);

1 个答案:

答案 0 :(得分:0)

您忘了在Option对象中选择: dialogReturnValueCallback

您可以将函数传递给此参数。当模态关闭时(好,取消......)将执行此功能。

做这样的事情:

function OpenDialog(url)
{
  var dialogOptions = SP.UI.$create_DialogOptions();
  dialogOptions.url = url // URL of the Page
  dialogOptions.title = 'Dialog Window'
  dialogOptions.allowMaximize= true
  dialogOptions.width = 635; // Width of the Dialog
  dialogOptions.height = 335; // Height of the Dialog
  dialogOptions.dialogReturnValueCallback = Function.createDelegate(null,DialogCallback )

  SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
}
function DialogCallback(result, target) {
   if (result == SP.UI.DialogResult.OK) {
        //Close the Modal with the function : SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, returnValue);

        //Here Your First Modal is close normaly, open Your New Modal Dialog

   }else if (result == SP.UI.DialogResult.cancel){
        //Close the modal with the function : SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,returnValue); 
   } else{
        //The user have closed the modal with the cross 
   }
}

所以在你的父页面中,jsute调用:

OpenDialog(url);

在你的第一个模态中,正式关闭模态:

SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, "a value to return ...");

然后将执行DialogCallback函数,然后您可以打开新的Modal