SharePoint 2013中使用SP.UI.ModalDialog.showModalDialog时showModalDialog未定义的解决办法

本文讲述SharePoint 2013 中使用 SP.UI.ModalDialog.showModalDialog时 showModalDialog  未定义的问题。 

  1.  function DialogCallback(dialogResult, returnValue)  
  2.           {                                          
  3.              if (returnValue == '1') {  
  4.              alert("operation successfully");  
  5.               }     
  6.     }            
  7.  
  8.  var options = {    
  9.                        url:'url',    
  10.                         600,    
  11.                        height: 630,    
  12.                        dialogReturnValueCallback: DialogCallback  
  13.                       };     
  14.  
  15. SP.UI.ModalDialog.showModalDialog(options);                

上面的代码在SharePoint 2010中是可以正常工作的,就是显示一个 有模式的窗口。

但在SharePoint  2013 中会出现 (ModalDialog )showModalDialog  未定义的错误,如何解决这个问题呢?使用  SP.SOD.executeFunc :

  1. function DialogCallback(dialogResult, returnValue)  
  1.          {                                          
  2.             if (returnValue == '1') {  
  3.             alert("operation successfully");  
  4.              }     
  5.    }            
  6.  
  1. var options = {    
  1.                       url:'url',    
  2.                        600,    
  3.                       height: 630,    
  4.                       dialogReturnValueCallback: DialogCallback  
  5.                      };   
  6.    
  7. SP.SOD.executeFunc(  
  8.      'sp.ui.dialog.js',  
  9.      'SP.UI.ModalDialog.showModalDialog',   
  10.      function(){  
  11.           SP.UI.ModalDialog.showModalDialog(options);});