我不晓得 为什么封装成类就变成这样了
Grid 不能动态添加数据这是为什么呢!
var myData = [
{personname:'集发',tel:'123456',fax:'123456',mobile:'123456'}
]
var countrydata = [
{id:1,name:'美国',date:7},{id:1,name:'日本',date:8}]
/*******************************************************/
var yeardata = [
{year:'2010年',value:'2010'},
{year:'2011年',value:'2011'},
{year:'2012年',value:'2012'},
{year:'2013年',value:'2013'}
];
var yearstore = new Ext.data.JsonStore({
data:yeardata,
autoLoad:true,
fields:['year','value']
});
/**************能否告诉我为什么我执行这个方法后Gird里的数据为增加呢*****************************/
function addrec(grid){
var mystore = grid.store;
alert(mystore);
var r = new Ext.data.Record({id:2,name:'s',date:'1'});
alert(r);
alert(mystore.getCount());
mystore.add(r);
var a = mystore.getCount();
for (var index = 0; index < a; index++) {
var s = mystore.getAt(index);
alert(s.get('name'));
}
}
Ext.apply(Ext.form.VTypes, {
daterange : function(val, field) {
var date = field.parseDate(val);
if(!date){
return;
}
if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
var start = Ext.getCmp(field.startDateField);
start.setMaxValue(date);
start.validate();
this.dateRangeMax = date;
}
else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
var end = Ext.getCmp(field.endDateField);
end.setMinValue(date);
end.validate();
this.dateRangeMin = date;
}
/*
* Always return true since we're only using this vtype to set the
* min/max allowed values (these are tested for after the vtype test)
*/
return true;
},
getdays: function(val, field){
var forms = field.ownerCt.ownerCt.ownerCt.ownerCt.ownerCt.getForm();
try{
var s = forms.findField('cfrq').parseDate(forms.findField('cfrq').getValue());
var o = field.parseDate(val);
var days = parseInt((o-s)/1000/60/60/24);
if(days<0){
return false
}
var d = forms.findField('zwts');
d.setValue(days+'');
}catch(e){
msg('系统提示',e.description,Ext.MessageBox.ERROR);
}
return true;
/*var days = parseInt((field-s)/1000/60/60/24);
if(days<0){
msg('系统提示','回国日期应该大于出访日期',Ext.MessageBox.ERROR);
}*/
},
getdaysText:'回国日期应该大于出访日期',
datecheck : function(val, field) {
var o = field.parseDate(val);
var d = new Date();
var days = parseInt(Math.abs(o-d)/1000/60/60/24);
if(days<=60)
{
return false;
}
return true;
},
datecheckText : '应该提前60天申报出国(境)任务'
});
/*********创建出国临时任务表单LinShiChuGuoForm************ */
LinShiChuGuoForm = Ext.extend(Ext.form.FormPanel, {
constructor : function() {
LinShiChuGuoForm.superclass.constructor.call(this, {
labelAlign : 'left',
frame : true,
id:'contactperson',
// fileUpload : true,
animCollapse : true,
labelWidth :90,
// width : 400,
autoScroll:true,
items : [
{
xtype:'tabpanel',
deferredRender:false,
plain:true,
activeTab: 0,
height:400,
autoScroll:true,
defaults:{bodyStyle:'padding:10px'},
items:[
{
title:'具体信息',
plain:true,
frame:true,
layout:'form',
defaults:{xtype : 'textfield'},
items:[
{
xtype:'panel',
layout:'column',
items: [
{
columnWidth:.3,
layout: 'form',
defaults: {anchor:'90%'},
defaultType: 'textfield',
border:false,
items:[
{
name:'sbbh',
fieldLabel: '申报编号'
},
{
name:'sbdw',
value:shenbaodanwei,
fieldLabel: '申报单位'
},
{
name:'tzmc',
fieldLabel: '团组名称',
allowBlank: false,
blankText:'请填写团组名称!',
emptyText:'请填写团组名称'
},
{
name:'cgnf',
xtype: "combo",
mode:'local',
triggerAction:'all',
store:yearstore,
value : '2010',
valueField:'value',
displayField:'year',
fieldLabel: '<font color="red" size=3>*</font>出国年份'
},
{
name:'tzzrs',
xtype: 'numberfield',
fieldLabel: '<font color="red" size=3>*</font>团组总人数',
allowBlank: false,
blankText:'请填写团组总人数,为阿拉伯数字格式!',
maxValue: 10,
maxText:'团组总人数不能超过10人',
minValue: 1,
minText:'团组总人数不能少于1人',
emptyText:'请填写团组总人数,数字格式'
},
{
name:'sbdwrs',
xtype: "numberfield",
fieldLabel: '<font color="red" size=3>*</font>申报单位人数',
allowBlank: false,
maxValue: 10,
minValue: 1,
maxText:'申报单位人数不能超过10人',
minText:'申报单位人数不能少于1人',
blankText:'申报单位人数不能为空!',
emptyText:'请填写申报单位人数'
},
{
name:'zlwrs',
xtype: "numberfield",
fieldLabel: '<font color="red" size=3>*</font>中铝外人数',
allowBlank: false,
blankText:'请填写中铝系统外人数,为阿拉伯数字格式!',
maxValue: 10,
maxText:'中铝系统外人数不能超过10人',
minValue: 0,
emptyText:'请填写中铝系统外人数,数字格式'
}
]
},
{
columnWidth:.3,
layout: 'form',
defaults: {anchor:'90%'},
defaultType: 'textfield',
border:false,
bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
style: {
"margin-left": "10px",
"margin-right": Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0"
},
items:[
{
xtype: "numberfield",
fieldLabel: '<font color="red" size=3>*</font>承担费用人数',
allowBlank: false,
blankText:'请填写申报单位承担费用人数,为阿拉伯数字格式!',
emptyText:'申报单位承担费用人数,数字格式',
maxValue: 10,
minValue: 1,
maxText:'承担费用人数不能超过10人',
listeners:{'change':function(){
/*var cfstore = Ext.getCmp('cfdays').store;
if(cfstore.getCount()>0)
{
updateall();
calctransformfee();//改变交通费用
}*/
}},
id:'cdfyrs',
name: 'cdfyrs'
},
{
name:'cfyf',
xtype: "combo",
mode:'local',
triggerAction:'all',
store:monthstore,
valueField:'value',
displayField:'month',
fieldLabel: '出访月份'
},
{
name:'cfrq',
xtype:'datefield',
vtype:'datecheck',
format:'Y-m-d',
fieldLabel: '出访日期'
},
{
name:'hgrq',
xtype:'datefield',
format:'Y-m-d',
vtype:'getdays',
/*listeners:{'select':function(m,d){
var forms = m.ownerCt.ownerCt.ownerCt.ownerCt.ownerCt.getForm();
var s = forms.findField('cfrq').parseDate(forms.findField('cfrq').getValue());
var days = parseInt((d-s)/1000/60/60/24);
if(days<0){
msg('系统提示','回国日期应该大于出访日期',Ext.MessageBox.ERROR);
}
}},*/
fieldLabel: '回国日期'
},{
name:'zwts',
readOnly:true,
fieldLabel:'在外天数'
},
{
name:'ztdw',
xtype:'combo',
mode:'remote',
value:shenbaodanwei,
triggerAction:'all',
store:ztdwstore,
valueField:'text',
displayField:'text',
typeAhead : true,
queryParam:'query',
fieldLabel: '<font color="red" size=3>*</font>组团单位'
},{
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>组团单位性质',
name:'ztdwxz',
mode:'remote',
triggerAction:'all',
store:ztdwxzstore,
valueField:'text',
displayField:'text'
}
]
},
{
columnWidth:.3,
layout: 'form',
defaults: {anchor:'90%'},
defaultType: 'textfield',
border:false,
bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
style: {
"margin-left": "10px",
"margin-right": Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0"
},
items:[
{
name:'tzlb',
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>团组类别',
mode:'remote',
triggerAction:'all',
store:tzlbstore,
valueField:'text',
displayField:'text',
value:''
},
{
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>团组性质',
name: 'tzxz',
mode:'remote',
triggerAction:'all',
value:'商务和经费洽谈',
store:tzxzstore,
valueField:'text',
displayField:'text'
},
{
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>自组团/双跨 ',
name: 'zztsk',
mode:'remote',
triggerAction:'all',
store:zztskstore,
value:'自组团',
valueField:'text',
displayField:'text'
},{
xtype:'label',
text:'(双跨为参加中铝系统外单位组团出访)'
},
{
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>计划内/外',
name: 'jhnw',
mode:'remote',
triggerAction:'all',
store:jhnjhwstore,
valueField:'value',
displayField:'text',
value:'计划内'
},
{
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>经费来源',
store:jflystore,
valueField:'text',
displayField:'text',
value:'项目经费',
mode:'remote',
triggerAction:'all',
name: 'jfly'
},
{
xtype:'combo',
fieldLabel: '<font color="red" size=3>*</font>经费性质',
name: 'jfxz',
mode:'remote',
triggerAction:'all',
store:jfxzstore,
valueField:'text',
displayField:'text',
value:'行政管理费用'
},
{
xtype:'combo',
fieldLabel: '<font color="red" size=3> </font>费用归属',
name: 'fygs',
mode:'remote',
store:fygsstore,
valueField:'text',
displayField:'text',
triggerAction:'all'
}
]
}
]
}
,
{
xtype:'textfield',
allowBlank: false,
blankText:'请认真填写出访事由(不能少于15个字)!',
emptyText:'填写出访事由(不能少于15个字)',
minLength:15,
minLengthText:'请认真填写出访事由(不能少于15个字)!',
name:'cfsy',
id:'cfsy',
anchor:'85%',
enableKeyEvents:true,
fieldLabel: '<font color="red" size=3>*</font>出访事由(不少于15个字)',
listeners:{
keyup:function(src,e){
var strs = '<font color="red" size=3>*</font>出访事由(不少于15字)';
strs += ' 已经输入了'+src.getValue().length+'字';
Ext.DomQuery.selectNode('label[for=cfsy]').innerHTML=strs
}
}
},
{
name:'bz',
anchor:'85%',
fieldLabel: '备注'
}]
},{
title:'出访地区和时间',
// layout:'column',
frame:true,
border:true,
items:[
{
xtype:'button',
text:'添加数据',
handler:function(){
var mygrid = Ext.getCmp('rcap');
/********************************************************************/
/*************想在这里给名叫rcap的Grid添加数据如何写呢?******************/
addrec(mygrid);
}
},
{
layout:'fit',
xtype:'grid',
store:new Ext.data.JsonStore({
data:countrydata,
autoLoad:true,
fields:['id','name','date']
}),
name:'rcap',
id:'rcap',
width:500,
heigth:500,
cm:new Ext.grid.ColumnModel([
{header:'国家',dataIndex:'name',width: 200, sortable: true},
{header:'天数',dataIndex:'date',width: 100, sortable: true}]
)
}
]
},{
title:'费用信息',
layout:'column',
frame:true,
border:false,
items:[
{
columnWidth:.5,
layout: 'form',
labelAlign : 'top',
border:false,
items: [{
xtype:'numberfield',
fieldLabel: '<font color="red">团组机票费用(系统参考值为出访三个国家地区的最高费用)(人民币元)* <br/>公务舱乘坐人员为:总部部室主任、副主任及企业党政一把手</font><br/> 机票经济舱人数 ',
name: 'jjcrs',
/*listeners:{'change':function(f,nvalue,ovalue){
var jjcfy = Ext.getCmp('jjcfy');
var gwcfy = Ext.getCmp('gwcfy');
var tdcfy = Ext.getCmp('tdcfy');
var jpxj = Ext.getCmp('jpxj');//机票小计
var mv = nvalue*22000;
jjcfy.setValue(mv);
var st = jjcfy.getValue()+gwcfy.getValue()+tdcfy.getValue();
jpxj.setValue(st);
calctotal();
}},*/
anchor:'95%'
}, {
xtype:'numberfield',
fieldLabel: '经济舱机票费用(人民币元)<font color="red">参考:经济舱22000元/人 </font>',
name: 'jjcfy',
/*id:'jjcfy',
listeners:{'change':function(f,nvalue,ovalue){
var jjcfy = Ext.getCmp('jjcfy');
var gwcfy = Ext.getCmp('gwcfy');
var tdcfy = Ext.getCmp('tdcfy');
var jpxj = Ext.getCmp('jpxj');//机票小计
var st = jjcfy.getValue()+gwcfy.getValue()+tdcfy.getValue();
jpxj.setValue(st);
calctotal();
}},*/
anchor:'95%'
},{
xtype:'numberfield',
fieldLabel: '机票公务舱人数',
name: 'gwcrs',
/*listeners:{'change':function(f,nvalue,ovalue){
var gwcfy = Ext.getCmp('gwcfy');
var jjcfy = Ext.getCmp('jjcfy');
var tdcfy = Ext.getCmp('tdcfy');
var jpxj = Ext.getCmp('jpxj');
var mv = nvalue*60000;
gwcfy.setValue(mv);
var st = jjcfy.getValue()+gwcfy.getValue()+tdcfy.getValue();
jpxj.setValue(st);
calctotal();
}},*/
anchor:'95%'
}, {
xtype:'numberfield',
fieldLabel: '公务舱机票费用(人民币元)<font color="red">参考:公务舱60000元/人</font>',
name: 'gwcfy',
id:'gwcfy',
/* listeners:{'change':function(f,nvalue,ovalue){
var jjcfy = Ext.getCmp('jjcfy');
var gwcfy = Ext.getCmp('gwcfy');
var tdcfy = Ext.getCmp('tdcfy');
var jpxj = Ext.getCmp('jpxj');//机票小计
var st = jjcfy.getValue()+gwcfy.getValue()+tdcfy.getValue();
jpxj.setValue(st);
calctotal();
}},*/
anchor:'95%'
}, {
xtype:'numberfield',
fieldLabel: '机票头等舱人数',
name: 'tdcrs',
/* listeners:{'change':function(f,nvalue,ovalue){
var gwcfy = Ext.getCmp('gwcfy');
var jjcfy = Ext.getCmp('jjcfy');
var tdcfy = Ext.getCmp('tdcfy');
var mv = nvalue*80000;
var jpxj = Ext.getCmp('jpxj');
tdcfy.setValue(mv);
var st = jjcfy.getValue()+gwcfy.getValue()+tdcfy.getValue();
jpxj.setValue(st);
calctotal();
}},*/
anchor:'95%'
}, {
xtype:'numberfield',
fieldLabel: '头等舱机票费用(人民币元)<font color="red">参考:头等舱80000元/人</font>',
name: 'tdcfy',
/* id:'tdcfy',
listeners:{'change':function(f,nvalue,ovalue){
var jjcfy = Ext.getCmp('jjcfy');
var gwcfy = Ext.getCmp('gwcfy');
var tdcfy = Ext.getCmp('tdcfy');
var jpxj = Ext.getCmp('jpxj');//机票小计
var st = jjcfy.getValue()+gwcfy.getValue()+tdcfy.getValue();
jpxj.setValue(st);
calctotal();
}},*/
anchor:'95%'
}]
},{
columnWidth:.5,
layout: 'form',
labelAlign : 'top',
border:false,
items: [
{
xtype:'numberfield',
fieldLabel: '<font color="red" size=3>*</font>机票费用小计(人民币元)',
name: 'jpxj',
readOnly:true,
// id:'jpxj',
anchor:'95%'
},
{
xtype:'numberfield',
fieldLabel: '<font color="red" size=3>*</font>住宿伙食工杂费小计(人民币元)',
name: 'zhrmb',
/* id:'zhrmb',
listeners:{'change':function(f,nvalue,ovalue){
calctotal();
}},*/
anchor:'95%'
}, {
xtype:'numberfield',
fieldLabel: '<font color="red" size=3>*</font>城市交通费小计(人民币元)',
name: 'csjjtfyzhrmb',
/*id:'csjjtfyzhrmb',
listeners:{'change':function(f,nvalue,ovalue){
calctotal();
}},*/
anchor:'95%'
},
{
xtype:'numberfield',
fieldLabel: '<font color="red" size=3>*</font>个人零用费小计(人民币元)',
name: 'grlybzzhrmb',
/*id:'grlybzzhrmb',
listeners:{'change':function(f,nvalue,ovalue){
calctotal();
}},*/
anchor:'95%'
},{
xtype:'numberfield',
fieldLabel: '<font color="red" size=3>*</font>不可预见费小计(人民币元)<br><font color="red">(包括展览费、培训费、会议注册费,其他费用请在备注里说明)</font>',
name: 'bkyjfzhrmb',
/*id:'bkyjfzhrmb',
listeners:{'change':function(f,nvalue,ovalue){
calctotal();
}},*/
anchor:'95%'
}, {
xtype:'numberfield',
fieldLabel: '<font color="red" size=3>*</font>费用合计(人民币元)',
name: 'zfyxj',
// id: 'zfyxj',
anchor:'95%'
}]
}
]
},{
title:'联系人信息',
plain:true,
frame:true,
layout:'column',
items: [
{
columnWidth: 0.7,
xtype: 'fieldset',
labelWidth:100,
defaults: {width: 150,anchor:'95%'},
defaultType: 'textfield',
autoHeight: true,
bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
border: false,
style: {
"margin-left": "10px",
"margin-right": Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0"
},
items: [
{
fieldLabel: '联系人姓名',
name: 'lxrxm'
},
{
fieldLabel: '联系人电话',
name: 'lxrdh'
},{
fieldLabel: '联系人手机',
name: 'lxrsj'
},
{
fieldLabel: '联系人传真',
name: 'lxrcz'
}
]
}
]
},{
title:'邀请方信息',
plain:true,
frame:true,
layout:'column',
items: [
{
columnWidth: 0.7,
xtype: 'fieldset',
labelWidth:100,
defaults: {width: 150,anchor:'95%'},
defaultType: 'textfield',
autoHeight: true,
bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
border: false,
style: {
"margin-left": "10px",
"margin-right": Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0"
},
items: [
{
fieldLabel: '邀请方姓名',
name: 'yqfxm'
},
{
fieldLabel: '邀请方单位名称',
name: 'yqfdwmc'
},{
fieldLabel: '邀请方职务',
name: 'yqfzw'
},
{
fieldLabel: '邀请方电话',
name: 'yqfdh'
},
{
fieldLabel: '邀请方地址',
name: 'yqfdz'
}
]
}
]
},{
title:'出国人员信息',
plain:true,
frame:true,
layout:'column',
items: []
}]
}]
}
);
},
getValue:function(){
if(this.getForm().isValid()){
return new Ext.data.Record(this.getForm().getValues());
}else{
throw Error('表单未能通过!');
}
},
setValue:function(_r){
this.getForm().loadRecord(_r);
},
reset:function(){
this.getForm().reset();
}
});
/** ******创建BigTypeForm结束************ */
/** ******创建BigTypeWindow开始********** */
LinShiChuGuoWindow = Ext.extend(Ext.Window, {
form : null,
constructor : function() {
this.form = new LinShiChuGuoForm();
LinShiChuGuoWindow.superclass.constructor.call(this, {
plain : true,
autoScroll : true,
width : 417,
height : 220,
autoShow:true,
modal : true,
maximized:true,
layout: 'fit',
// minimizable:true,
// maximizable:true,
minWidth:200,
minHeight:200,
items : this.form,
closeAction : 'hide',
buttonAlign : 'center',
buttons : [{
text : '确定',
handler : this.onSubmitClick,
scope : this
}, {
text : '取消',
handler : this.onCancelClick,
scope : this
}]
});
this.addEvents('submit');
},
close : function() {
this.form.reset();
this.hide();
},
onCancelClick : function() {
this.close();
},
onSubmitClick : function() {
try {
var valflag = this.form.getForm().isValid();
if (valflag) {
this.fireEvent('submit', this, this.form.getValue());
} else {
msg('系统提示', '请填写正确信息!', Ext.MessageBox.ERROR);
}
} catch (_err) {
msg('系统提示', _err.description, Ext.MessageBox.ERROR);
return;
}
},
onCanelClick : function() {
this.close();
}
});
/*********创建BigTypeWindow结束**************/
/***/
InsertLinShiChuGuoWindow = Ext.extend(LinShiChuGuoWindow, {
title : '添写临时出国申请单',
gettaskid:function(taskid){
/***********李庆柱2010-03-09 添加为了获取Task临时出国审批标识*****************/
var me = this.form;
var requestproperties = function(params,url){
return {
url: url,
params:params,
customer:'自定义属性',
method:'POST',
callback:function(options,success,response){
//响应函数
var jsonarray = Ext.util.JSON.decode(response.responseText);
var ps = params;
var str = response.responseText;
var sbbh = jsonarray.planid;
me.getForm().findField('sbbh').setValue(sbbh);
}
}
};
var url = '../../../back/TemporaryTaskaction_getShenBaoBianHao.action';
var requestConfig = requestproperties(null,url);
Ext.Ajax.request(requestConfig);
/***********李庆柱2010-03-09 结束******************/
}
});
/***/
UpdateLinShiChuGuoWindow = Ext.extend(LinShiChuGuoWindow, {
title : '修改大类',
load : function(_r) {
this.form.setValue(_r);
}
});