Extjs4中导入自己写的JS显示不正常而直接写在jsp页面又正常
我是初学者,刚接触js,如题所示,将代码直接写在jsp页面中能正常显示但是我想把js写在专门的文件中,然后引入到页面中,但是就显示不正常了,求大神们指导,代码如下:
Ext.onReady(function(){extjs4 引入 JavaScript
//创建数据表格
var datas = [
['张三','男',true,new Date(1988,02,12),2500],
['李四','男',false,new Date(1989,03,22),3500],
['小红','女',false,new Date(1989,03,22),3500],
['李四','男',false,new Date(1989,03,22),3500],
['李四','男',false,new Date(1989,03,22),3500],
['小花','女',false,new Date(1989,03,22),3500],
['李四','男',false,new Date(1989,03,22),3500],
['小萌','女',false,new Date(1989,03,22),3500],
['李四','男',false,new Date(1989,03,22),3500],
['小敏','男',true,new Date(1989,12,12),2500]
];
//创建Grid表格组件
Ext.create('Ext.grid.Panel',{
title : 'Grid示例',
renderTo : Ext.getBody(),
width : 600,
hegiht : 350,
frame : true,
viewConfig:{
forceFit : true,
stripeRows : true //在表格中显示斑马线
},
store : { //配置数据源
fields : ['name','sex','leader','birthday','salary'], //定义字段
groupField : 'sex',//设置分组字段
proxy : {
type : 'memory', //Ext.Date.proxy.Memory内存代理
data : datas, //读取内嵌数据
reader : 'array' //Ext.data.reader.Array解析器
},
autoLoad : true //自动加载
},
plugins:[Ext.create('Ext.grid.plugin.CellEditing',{
clicksToEdit : 2//设置鼠标单击一次进入编辑状态
})
],
setType : 'cellmodel',//设置为单元格选择模式
features:[Ext.create('Ext.grid.feature.Grouping',{
groupByText : '用本字段分组',
showGroupsText : '显示分组',
groupMeaderTp1 : '性别:{name} ({rows.length})',//分组标题模板
startCollapsed : true //设置初始分组是否收起
}),
{
ftype: 'summary'//Ext.grid.feature.Summary表格汇总特性
}],
columns : [ //配置表格列
{header : "行号" ,width : 35,
xtype: 'rownumberer' //Ext.grid.column.RowNumberer
},
{header : "姓名" ,width : 80,dataIndex :'name',flex: 1,
summaryType:'count',//求数量
summaryRenderer:function(value){
return '员工总数:'+value
},
editor:{//文本字段
xtype:'textfield',
allowBlank:false //不允许字段为空
}
},
{header : "性别" ,width : 80,dataIndex :'sex',renderer:formatSex},
{header : "组长" ,width : 80,dataIndex :'leader',
xtype : 'booleancolumn',//Ext.grid.column.Boolean布尔列
trueText : '是',
falseText : '否'
},
{header : "生日" ,width : 120,dataIndex :'birthday',
xtype : 'datecolumn',//Ext.grid.column.Date日期列
format : 'Y年m月d日' ,//日期格式化字符串
editor:{//日期字段
xtype : 'datefield',
allowBlank:false
}
},
{header : "薪水" ,width : 120,dataIndex :'salary',flex : 1,
xtype : 'numbercolumn',//Ext.grid.column.Number数字列
format : '0,000', //数字格式化字符串
summaryType : 'average',//求平均值
summaryRenderer : function(value){
return '平均工资:'+ value
},
editor:{//数字字段
xtype : 'numberfield',
allowBlank:false
}
},
{header : "操作" ,width : 80,
xtype : 'actioncolumn',//Ext.grid.column.Action动作列
items : [{
icon : 'images/edt.gif',//指定编辑的图标资源的路径
handler : function(grid,rowIndex,colIndex){
//获取被操作的数据记录
var rec = grid.getStore().getAt(rowIndex);
alert("编辑 "+rec.get('name'));
}
},
{
icon : 'images/del.gif',//指定编辑的图标资源的路径
handler : function(grid,rowIndex,colIndex){
//获取被操作的数据记录
var rec = grid.getStore().getAt(rowIndex);
alert("删除"+rec.get('name'));
}
},
{
icon : 'images/add.gif',//指定编辑的图标资源的路径
handler : function(grid,rowIndex,colIndex){
//获取被操作的数据记录
var rec = grid.getStore().getAt(rowIndex);
alert("保存 "+rec.get('name'));
}
}]
}
]
});
//定义渲染函数,格式化性别显示
function formatSex(value){
return value=='男'?'男':'<font color=red>女</font>';
}
});