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){ }


猜你喜欢

转载自blog.csdn.net/shan1774965666/article/details/78486456