问题描述
/ 定义Proxyvar proxy = new Ext.data.HttpProxy({url : "plantsAction!getPlantsById.action"});var Order = Ext.data.Record.create([{name : "cabinetName",type : "string",mapping : "cabinetName"}, {name : "cabinetNO",type : "string",mapping : "cabinetNO"}, {name : "cabinetModel",type : "string",mapping : "cabinetModel"}, {name : "cabinetLocation",type : "string",mapping : "cabinetLocation"}, {name : "cabinetType",type : "string",mapping : "cabinetType"}, {name : "cabinetDutyRoleName",type : "string",mapping : "cabinetDutyRoleName"}, {name : "cabinetId",type : "string",mapping : "cabinetId"}, {name : "cabinetNotes",type : "string",mapping : "cabinetNotes"}, {name : "id",type : "int",mapping : "id",hidden : true}]);// 定义Readervar reader = new Ext.data.JsonReader({totalProperty : "totalCount",root : "data"}, Order);// 定义Storevar devstore = new Ext.data.Store({proxy : proxy,reader : reader});var devBoxAddrs = [["303", "303"], ["405", "405"]];// 定义列模型var cm = new Ext.grid.ColumnModel([{header : "机柜名称",dataIndex : "cabinetName",width : 120,align : "center",sortable : true}, {header : "机柜编号",dataIndex : "cabinetNO",width : 100,align : "center",sortable : true}, {header : "型号",dataIndex : "cabinetModel",width : 90,align : "center",sortable : true}, {header : "位置",dataIndex : "cabinetLocation",width : 100,align : "center",sortable : true}, {header : "规格类别",dataIndex : "cabinetType",width : 120,align : "center",sortable : true}, {header : "负责岗位",dataIndex : "cabinetDutyRoleName",width : 100,align : "center",sortable : true}, {id : "cabinetNotes",header : "描述",dataIndex : "cabinetNotes",width : 150,align : "center",sortable : true}]);// 分页控件 其实分页还是要后台控制的var pagingBar = new Ext.PagingToolbar({autoWidth : true,pageSize : 10,displayInfo : true,emptyMsg : "没有数据显示",displayMsg : "显示从{0}条到{1}条数据,共{2}条数据",store : devstore,loadMask : true});// 定义EditGridPanelvar useGrid = new Ext.grid.GridPanel({title : "已安装机柜列表视窗",store : devstore,cm : cm,// renderTo:"a",autoExpandColumn : "cabinetNotes",autoWidth : true,// height : 150,autoEncode : true, // 提交时是否自动编码tbar : ["-", {text : "增加机柜",icon : "../../../extjs/resources/images/default/dd/drop-add.gif",handler : function() {cabWin.show();}}, "-", {text : "删除机柜",icon : "../../../extjs/resources/images/default/dd/drop-no.gif",cls : "x-btn-text-icon",handler : function() {var sm = useGrid.getSelectionModel();if (sm.hasSelection()) {Ext.Msg.confirm("提示", "真的要删除选中的行吗?", function(btn) {if (btn == "yes") {var rsm = useGrid.getSelectionModel();// 得到行选择模型var cabid = 0;var view = useGrid.getView();var store = useGrid.getStore();for (var i = view.getRows().length - 1; i >= 0; i--) {if (rsm.isSelected(i)) {cabid = useGrid.getStore().getAt(i).get("cabinetId")+ "," + cabid;store.remove(store.getAt(i));}}alert(cabid);Ext.Ajax.request({url : "cabinetAction!deleteCabinet.action?ids="+ cabid,success : function(response, config) {Ext.Msg.alert("提示", "删除客户端成功");var view = useGrid.getView();var store = useGrid.getStore();view.refresh();alert(useGrid.getStore().getAt(0).get("cabinetId"));devstore.load({params : {plantId : useGrid.getStore().getAt(0).get("cabinetId"),start : 0,limit : 10}})},failure : function() {Ext.Msg.alert("result:", "get failed");},method : "get"})}});} else {Ext.Msg.alert("错误", "请先选择删除的行,谢谢!");}}}, "-"],bbar : pagingBar});后台输出的JSON数据{"data":[{"FState":0,"address":"","cabinetDutyRoleId":"1","cabinetDutyRoleName":"系统管理员","cabinetDutyUserID":"1","cabinetDutyUserName":"邢涛 ","cabinetId":"8","cabinetLocation":"36#","cabinetModel":"42U","cabinetNO":"1#","cabinetName":"专用机柜1","cabinetNotes":"888888888","cabinetType":"服务器机柜","countCabinet":0,"createTime":"","creatorId":0,"deptId":0,"deptName":"","id":0,"name":"","notes":"","plantsNO":"","purpose":""},{"FState":0,"address":"","cabinetDutyRoleId":"1","cabinetDutyRoleName":"系统管理员","cabinetDutyUserID":"1","cabinetDutyUserName":"邢涛 ","cabinetId":"2","cabinetLocation":"1","cabinetModel":"1","cabinetNO":"2","cabinetName":"1","cabinetNotes":"1","cabinetType":"1","countCabinet":0,"createTime":"","creatorId":0,"deptId":0,"deptName":"","id":0,"name":"","notes":"","plantsNO":"","purpose":""},{"FState":0,"address":"","cabinetDutyRoleId":"1","cabinetDutyRoleName":"系统管理员","cabinetDutyUserID":"1","cabinetDutyUserName":"邢涛 ","cabinetId":"6","cabinetLocation":"36#","cabinetModel":"42U","cabinetNO":"3#","cabinetName":"专用机柜2","cabinetNotes":"888888888fdsgad","cabinetType":"其他","countCabinet":0,"createTime":"","creatorId":0,"deptId":0,"deptName":"","id":0,"name":"","notes":"","plantsNO":"","purpose":""},{"FState":0,"address":"","cabinetDutyRoleId":"1","cabinetDutyRoleName":"系统管理员","cabinetDutyUserID":"1","cabinetDutyUserName":"邢涛 ","cabinetId":"9","cabinetLocation":"36#","cabinetModel":"42U","cabinetNO":"1#","cabinetName":"专用机柜1","cabinetNotes":"888888888","cabinetType":"服务器机柜","countCabinet":0,"createTime":"","creatorId":0,"deptId":0,"deptName":"","id":0,"name":"","notes":"","plantsNO":"","purpose":""}],"totalCount":4}但是页面只显示一条了;
解决方案
服务端返回的数据中每一条记录的id都是相同的,而JsonReader的idProperty默认配置是id,这就是出现问题的根源。你只要让每一条记录的id不同就行了。