1. 程式人生 > >artDialog實現子視窗向父元素傳遞資料

artDialog實現子視窗向父元素傳遞資料

案例:在頁面A點選按鈕,彈出artDialog視窗B,當關閉視窗B時,實現向父元素A傳遞資料。

一、方法一:

1、利用artdialog中的data方法進行傳值與接收值。

      在子視窗呼叫:artDialog.data('變數名',變數值) 進行傳值;  

      在父元素呼叫:art.dialog.data('變數名')  進行接收值; //可能需要在artDialog的close方法中

2、例項如下:

兩個頁面都要引入的js:

[javascript]  view plain  copy
  1. <script src="${base}/resource/artDialog/artDialog.source.js" type="text/javascript"></script>  
  2. <script src="${base}/resource/artDialog/iframeTools.source.js"
     type="text/javascript"></script>  

視窗B中的js:

[javascript]  view plain  copy
  1. function commitSave() {  
  2.     var ajxxUuid = jQuery(
    "#grid_ajxx").jqGrid('getGridParam','selrow');  
  3.     var nsrmc = $("#grid_ajxx").jqGrid('getCell',ajxxUuid,'xaAy.nsrmc');  
  4.       
  5.     if(ajxxUuid) {  
  6.         artDialog.data("ajxxUuid", ajxxUuid); //將值存起來,供父頁面讀取  
  7.         artDialog.data("nsrmc", nsrmc);  
  8.         art.dialog.close();  
  9.     }else {  
  10.         showTopMsg("請選中一行再提交!", 4000, 'error');  
  11.         return false;  
  12.     }  
  13. }  

頁面A中按鈕的js:

[javascript]  view plain  copy
  1. function chooseAj() {  
  2.      url = "${base}/illegalInfo/ajxxList?oper=${oper}";   
  3.      art.dialog.open(url, {  
  4.         id: 'ajxxList',  
  5.         title: '案件資訊',  
  6.         width: 650,  
  7.         height: 460,  
  8.         left: '50%',  
  9.         top: '50%',  
  10.         background: '#000000',  
  11.         opacity: 0.1,  
  12.         lock: true,  
  13.         resize: false,  
  14.         close: function () {   
  15.             var ajxxUuid = art.dialog.data('ajxxUuid'); // 讀取子視窗返回的資料  
  16.             var nsrmc = art.dialog.data('nsrmc'); // 讀取子視窗返回的資料                 
  17.             if (ajxxUuid !== undefined){  
  18.                 document.getElementById("ajxxUuid").value = ajxxUuid; //賦值到頁面A的input以顯示出來  
  19.                 document.getElementById("nsrmc").value = nsrmc;    
  20.             }   
  21.         }  
  22.     },  
  23.     false);  
  24.   
  25. }  

二、方法二

1、父元素與子視窗都呼叫同一個方法傳值

 子視窗   artDialog.opener.diliverDataToParent(chineseAddress, gis);  //diliverDataToParent為方法名,chineseAddressgis為兩個變數

 父元素    function diliverDataToParent(chinese, coordinate){ }


案例:在頁面A點選按鈕,彈出artDialog視窗B,當關閉視窗B時,實現向父元素A傳遞資料。

一、方法一:

1、利用artdialog中的data方法進行傳值與接收值。

      在子視窗呼叫:artDialog.data('變數名',變數值) 進行傳值;  

      在父元素呼叫:art.dialog.data('變數名')  進行接收值; //可能需要在artDialog的close方法中

2、例項如下:

兩個頁面都要引入的js:

[javascript]  view plain  copy
  1. <script src="${base}/resource/artDialog/artDialog.source.js" type="text/javascript"></script>  
  2. <script src="${base}/resource/artDialog/iframeTools.source.js" type="text/javascript"></script>  

視窗B中的js:

[javascript]  view plain  copy
  1. function commitSave() {  
  2.     var ajxxUuid = jQuery("#grid_ajxx").jqGrid('getGridParam','selrow');  
  3.     var nsrmc = $("#grid_ajxx").jqGrid('getCell',ajxxUuid,'xaAy.nsrmc');  
  4.       
  5.     if(ajxxUuid) {  
  6.         artDialog.data("ajxxUuid", ajxxUuid); //將值存起來,供父頁面讀取  
  7.         artDialog.data("nsrmc", nsrmc);  
  8.         art.dialog.close();  
  9.     }else {  
  10.         showTopMsg("請選中一行再提交!", 4000, 'error');  
  11.         return false;  
  12.     }  
  13. }  

頁面A中按鈕的js:

[javascript]  view plain  copy
  1. function chooseAj() {  
  2.      url = "${base}/illegalInfo/ajxxList?oper=${oper}";   
  3.      art.dialog.open(url, {  
  4.         id: 'ajxxList',  
  5.         title: '案件資訊',  
  6.         width: 650,  
  7.         height: 460,  
  8.         left: '50%',  
  9.         top: '50%',  
  10.         background: '#000000',  
  11.         opacity: 0.1,  
  12.         lock: true,  
  13.         resize: false,  
  14.         close: function () {   
  15.             var ajxxUuid = art.dialog.data('ajxxUuid'); // 讀取子視窗返回的資料  
  16.             var nsrmc = art.dialog.data('nsrmc'); // 讀取子視窗返回的資料                 
  17.             if (ajxxUuid !== undefined){  
  18.                 document.getElementById("ajxxUuid").value = ajxxUuid; //賦值到頁面A的input以顯示出來  
  19.                 document.getElementById("nsrmc").value = nsrmc;    
  20.             }   
  21.         }  
  22.     },  
  23.     false);  
  24.   
  25. }  

二、方法二

1、父元素與子視窗都呼叫同一個方法傳值

 子視窗   artDialog.opener.diliverDataToParent(chineseAddress, gis);  //diliverDataToParent為方法名,chineseAddressgis為兩個變數

 父元素    function diliverDataToParent(chinese, coordinate){ }