问题描述:刷新页面点击新增可以正确显示 添加form 和添加win添加完新纪录后,点击修改页面,修改页面渲染就出了问题反之亦然,主要体现在form的渲染有问题,要么看不见 要么出来的东西重复
大家帮忙看看吧!~~~详细EXTJS代码
/**
 * 通讯录管理
 */Ext.namespace("page.role");Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';//每页显示多少条记录
var pageSize = 14;
var addForm,addFormWin,editForm,editFormWin;
var addButton,delButton,editButton,purButton,grid;Ext.onReady(function(){

//多选框,支持点击取消
var sm = new Ext.grid.CheckboxSelectionModel({headerMouseDown: Ext.emptyFn()});
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
sm,
    {header:'角色编号',dataIndex:'id',width:150,sortable:true},
    {header:'角色名称',dataIndex:'name',width:250,sortable:true}, 
    {header:'备注',dataIndex:'re',width:300,sortable:true}
]);
var record = new Ext.data.Record.create([
{name: 'id',mapping:'id',type:'string'},
{name: 'name',mapping:'name',type:'string'},
{name: 're',mapping:'re',type:'string'}
]);

//表单数据源
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: './role/list'}),
baseParams :{start:0,limit:pageSize},
timeout: 90000,
reader: new Ext.data.JsonReader({
    totalProperty: 'totalCount',
    root: 'root'
},record),
//是否支持后台排序
remoteSort: true
});
store.load();

addButton = new Ext.Button({
text:'新增',
iconCls: 'page_add',
handler: function() {
addFormWin.show(this);
}
});
delButton = new Ext.Button({
text:'删除',
iconCls: 'page_delete',
handler: function() {
var selectAttribute = grid.getSelectionModel().getSelections();
if(selectAttribute.length==0) {
Ext.MessageBox.alert('提示','请选择要删除的记录!');
return;
}
Ext.Msg.confirm('提示','你确定要删除吗?',function(btn) {
if(btn=='yes') {
var ids = "";
for(var i=0 ; i<selectAttribute.length ; i++){
ids+=selectAttribute[i].get("id")+",";
}
Ext.Ajax.request({
url : './role/delete',
timeout: 90000,
method : 'POST',
waitMsg : '正在提交请求,请稍候...',
params : {
ids : ids
},
success : function(result,request) {
var results = Ext.decode(result.responseText);
if(results.success){
Ext.MessageBox.alert("成功",results.msg);
store.reload();
             }else{
             Ext.MessageBox.alert("失败",results.msg);
             }
},
failure : function() {
Ext.MessageBox.alert("提示","请求服务器失败!");
}
});
}
});

}
});
editButton = new Ext.Button({
text:'修改',
iconCls: 'page_edit',
handler: function() {
var att_rows = grid.getSelectionModel().getSelections();
if(att_rows.length == 0) {
Ext.MessageBox.alert('提示','请选择要修改的记录!');
return;
} else if(att_rows.length > 1) {
Ext.MessageBox.alert('提示','只能选择一项进行修改!');
return;
}
var att_row = att_rows[0];
editFormWin.show(this);
editForm.getForm().loadRecord(att_row);
}
});
purButton = new Ext.Button({
text:'权限设置',
iconCls: 'cog',
handler: function() {
Ext.MessageBox.alert("提示","未完成");
}
});

//工具栏
var tbar = new Ext.Toolbar([
'-',addButton,
'-',delButton,
'-',editButton,
'-',purButton,
'-'
]);
//分页工具栏
var pagingBar = new Ext.PagingToolbar({
pageSize: pageSize,
store: store,
displayInfo: true
});
//表格
grid = new Ext.grid.GridPanel({
     renderTo: 'grid',
        autoHeight: true,
        autoWidth:true,
        stripeRows: true,
        loadMask: {msg: '正在加载数据,请稍候...'},
        store: store,
        cm: cm,
        sm: sm, 
        tbar: tbar,
        bbar: pagingBar
    });

if(!addForm) {
addForm = new Ext.form.FormPanel({
labelAlign: 'right',
labelWidth: 60,
frame: true,
buttonAlign : 'center',
defaultType: 'textfield',
defaults : {width : 200},
items: [{
fieldLabel: '角色编号',
id: 'id',
name: 'role.id',
allowBlank : false,
blankText : '编号不能为空',
emptyText : '编号唯一',
listeners : {
'blur' : function() {
Ext.Ajax.request({
url : './role/checkRoleById?role.id='+Ext.get('id').getValue(),
method : 'POST',
timeout: 90000,
success : function(result,request) {
var results = Ext.decode(result.responseText);
if(results.success){
//this.Invalid('此角色名已存在');
Ext.MessageBox.alert("提示",'角色已存在');
}
}
});
}
}
},{
fieldLabel: '角色名称',
name: 'role.name',
allowBlank : false,
blankText : '名称不能为空'
},{
fieldLabel: '备注',
xtype: 'textarea',
height: 60,
name: 'role.re'
}
],
buttons : [{
text : '提交',
handler : function() {
if(!addForm.form.isValid()){
return;
}
addForm.form.submit( {
waitTitle: '提示',
waitMsg : '正在提交数据,请稍候...',
url : './role/add',
timeout: 90000,
method : 'POST',
success : function(form, action) {
if(action.result.success){
addFormWin.hide();
Ext.MessageBox.alert("成功",action.result.msg);
store.reload();
}else{
Ext.MessageBox.alert("失败",action.result.msg);
}
},
failure : function(form, action) {
Ext.MessageBox.alert('提示', "请求服务器失败!");
}
});
}
}, {
text : '重置',
handler : function() {
addForm.form.reset();
}
}]

});
}

if(!addFormWin) {
addFormWin = new Ext.Window({
title : '添加通讯录',
layout : 'fit', //自适应布局
width : 330,
height : 210,
plain : true,
bodyStyle : 'padding:5px;',
maximizable : false,
closeAction : 'hide',
modal:true,//模态对话框
plain : true,
// 将表单作为窗体元素嵌套布局
items : addForm
});
}

if(!editForm) {
editForm = new Ext.form.FormPanel({
labelAlign: 'right',
labelWidth: 60,
frame: true,
buttonAlign : 'center',
defaultType: 'textfield',
defaults : {width : 200},
items: [{
id: 'id',
fieldLabel: '角色编号',
readOnly:true,
name: 'role.id',
allowBlank : false,
blankText : '编号不能为空'
},{
fieldLabel: '角色名称',
id: 'name',
name: 'role.name',
allowBlank : false,
blankText : '名称不能为空'
},{
fieldLabel: '备注',
xtype: 'textarea',
height: 60,
id: 're',
name: 'role.re'
}
],
buttons : [{
text : '提交',
id : 'upSubmit',
handler : function() {
if(!editForm.form.isValid()){
return;
}
editForm.form.submit( {
waitTitle: '提示',
waitMsg : '正在提交数据,请稍候...',
url : './role/update',
timeout: 90000,
method : 'POST', 
success : function(form, action) {
if(action.result.success){
editFormWin.hide();
Ext.MessageBox.alert("成功",action.result.msg);
store.reload();
}else{
Ext.MessageBox.alert("失败",action.result.msg);
}
},
failure : function(form, action) {
Ext.MessageBox.alert('提示', "请求服务器失败!");
}
});
}
}, {
text : '取消',
handler : function() {
editFormWin.hide();
}
}]

});
}
if(!editFormWin) {
editFormWin = new Ext.Window({
title : '修改通讯录',
layout : 'fit', //自适应布局
width : 330,
height : 210,
plain : true,
bodyStyle : 'padding:5px;',
maximizable : false,
closeAction : 'hide',
modal:true,//模态对话框
plain : true,
// 将表单作为窗体元素嵌套布局
items : editForm
});
}

});