问题描述
一、操作1、点击新增入库 2、点击保存,父窗口数据不更新(已经确定数据库已经更新,并且已经确定调用了父窗口的方法refresh()) 3、点击关闭,为什么这个时候父窗口数据出现才会出现呢?(尝试过直接reload父页面,还是无法更新grid页面的数据,只用关闭子窗口时候,数据才会更新过去) 二、代码1、父页面代码,在onReady 方法中写了grid 实例化 和数据来源编写 Ext.onReady(function(){ XXXXX infostore = new Ext.data.JsonStore({ url:'../storage/stockIn.do?method=loadPlanDetails&simId=${planCode}', fields:[ {name:'sidAcceptancelistid',mapping:'sidAcceptancelistid'}, {name:'unit'}, {name:'spec'}, {name:'sidBatchno',mapping:'sidBatchno'}, {name:'sidId',mapping:'sidId'}, {name:'sidInamount',mapping:'sidInamount'}, {name:'sidInprice',mapping:'sidInprice'}, {name:'sidInsum',mapping:'sidInsum'}, {name:'sidMedicinecode',mapping:'sidMedicinecode'}, {name:'medName',mapping:'medName'}, {name:'sidMid',mapping:'sidMid'}, {name:'sidValiddate',mapping:'sidValiddate'}, {name:'sidWarningdate',mapping:'sidWarningdate'}, {name:'sidFactoryId',mapping:'sidFactoryId'}, {name:'sidFundSource'} ] }); grid = new Ext.grid.GridPanel({ store:infostore, columns:[ {name:'sidId',mapping:'sidId',dataIndex:'sidId',hidden:true}, {name:'sidMid',mapping:'sidMid',dataIndex:'sidMid',header:'入库单主表ID',hidden:true}, {name:'sidMedicinecode',mapping:'sidMedicinecode',dataIndex:'sidMedicinecode',header:'疫苗ID',hidden:true}, //{name:'sidAcceptancelistid',mapping:'sidAcceptancelistid',dataIndex:'sidAcceptancelistid',hidden:true}, {name:'medName',mapping:'medName',dataIndex:'medName',header:'疫苗',width:150}, {header:'单位',dataIndex:'unit',width:60}, {header:'规格',dataIndex:'spec',width:80}, {name:'sidBatchno',mapping:'sidBatchno',dataIndex:'sidBatchno',header:'批号'}, //{header:'资金来源',dataIndex:'sidFundSource',width:100}, {name:'sidInamount',mapping:'sidInamount',dataIndex:'sidInamount',header:'入库数量'}, {name:'sidInprice',mapping:'sidInprice',dataIndex:'sidInprice',header:'购进单价'}, {name:'sidInsum',mapping:'sidInsum',dataIndex:'sidInsum',header:'总金额'}, {name:'sidFactoryId',mapping:'sidFactoryId',dataIndex:'sidFactoryId',header:'生产厂家'}, {name:'sidValiddate',mapping:'sidValiddate',dataIndex:'sidValiddate',header:'有效日期'}, {name:'sidWarningdate',mapping:'sidWarningdate',dataIndex:'sidWarningdate',header:'失效报警日期'} ], //title:'明细', height:380, bodyStyle:'width:100%;align:center', frame:true, iconCls:'icon-grid', stripeRows:true, tbar:[ {text:'新增入库疫苗',handler:insertDetail1,iconCls:'add'},'-', {text:'修改',handler:update,iconCls:'edit'},'-', {text:'删除',handler:del,iconCls:'remove'} ] }); infostore.load({callback:disableSelect}); grid.addListener('rowdblclick', update); grid.render('grplist'); sm = grid.getSelectionModel(); refresh= function (){ //alert("dd"); //saveStockInm(1); //remove有反应, infostore.removeAll(); //reload没有反应 infostore.reload({callback:disableSelect}); grid.addListener('rowdblclick', update); grid.render('grplist'); sm = grid.getSelectionModel(); // window.location.reload(); //alert("ddddd333");} 2、父页面代码 弹出模态窗口function insertDetail2(){ //selectFromAccList.jsp var simId=stockinForm.simId.value; var providerId=stockinForm.simProviderid.value; if(providerId==null||providerId==''){ Ext.Msg.alert('提醒','请先选择供应单位!'); return; } var val = window.showModalDialog('stockIn.do?method=toAccList&simId='+simId+'&providerId='+providerId,window,'dialogWidth:650px; dialogHeight:470px; status:0; scroll:0;help:0; resizable:1'); if(val){ //saveStockInm(1); //infostore.removeAll(); //infostore.reload({callback:disableSelect}); }}3、子页面代码 , 调用 父窗口方法,数据不更新 parentWin.refresh(); parentWin.infostore.reload();var parentWin=window.dialogArguments; function add(){ if (!validate()) return; Ext.Ajax.request({ url:'../storage/stockIn.do?method=saveOneInDetail', form:'stockinForm', success:function(){ returnValue=true; //window.close(); parentWin.refresh(); parentWin.infostore.reload(); }, failure:function(){Ext.MessageBox.alert('提示', '发生错误....');} }); }
解决方案
解决办法:在子窗口中加入这个方法,在add的时候,将该执行该方法。//刷新父窗口;function refresh(){ Ext.Ajax.request({ parentWin.infostore.removeAll(); url:parentWin.infostore.url, success:function(response){ var data = Ext.util.JSON.decode(response.responseText); parentWin.infostore.loadData(data); }, failure:function(){Ext.MessageBox.alert('提示', '发生错误....');} });}