①extjs的字符串工具方法
1、ellipsis(String value,Number length)----截取字符串
[javascript] view plain copy
3. Ext.MessageBox.alert("ellipsis",Ext.util.Format.ellipsis(v,10));
截取v变量中的7个字,然后会在这7个字后面加上3个点,加起来一共10位;
2、Ext.util.Format.undef: ------将null装换成空字符串
[javascript] view plain copy
7. Ext.MessageBox.alert("undef",Ext.util.Format.undef(v));
3、Ext.util.Format.defaultValue:如果为空则赋默认值
[javascript] view plain copy
11. Ext.MessageBox.alert("defaultValue",Ext.util.Format.defaultValue(v,"这是默认值"));
4、Ext.util.Format.htmlEncode:将变量原样输出,而不进行html的解析
[javascript] view plain copy
14. var v="<a href=''>这是一个测试</a>";
15. Ext.MessageBox.alert("htmlEncode",Ext.util.Format.htmlEncode(v));
16. //Ext.MessageBox.alert("",v);
5、Ext.util.Format.htmlDecode:与htmlEncode相反,进行html的解析
[javascript] view plain copy
19. var v="<a href=''>这是一个测试</a>";
20. Ext.MessageBox.alert("htmlDecode",Ext.util.Format.htmlDecode(v));
21. //Ext.MessageBox.alert("",v);
6、Ext.util.Format.trim(String value):将字符串前后的空格删掉
[javascript] view plain copy
7、Ext.util.Format.substr(String value,Number start,Number lenght): 截取字符串
[javascript] view plain copy
29. Ext.MessageBox.alert("substr",Ext.util.Format.substr(v,1,5));
8、Ext.util.Format.lowercase(String value):将字符串转成小写
[javascript] view plain copy
33. Ext.MessageBox.alert("lowercase",Ext.util.Format.lowercase(v));
9、Ext.util.Format.uppercase(String value):将字符串转成大写
[javascript] view plain copy
37. Ext.MessageBox.alert("uppercase",Ext.util.Format.uppercase(v));
10、Ext.util.Format.capitalize(String value):第一个字母大写,其他字母小写
[javascript] view plain copy
41. Ext.MessageBox.alert("capitalize",Ext.util.Format.capitalize(v));
来源: http://blog.youkuaiyun.com/bzuld/article/details/8969770
.date(Mixed value,[String format]):将某个值解析成为一个特定格式的日期
[javascript] view plain copy
44. //Y:年;m:月;d:天;H:24小时制的小时;h:12小时制的小时;i:分;s:秒
46. Ext.MessageBox.alert("date",Ext.util.Format.date(v,'Y-m-d H:i:s'));
12、Ext.util.Format.skipTags(Mixed value):剥去value的html标签,只剩下文本内容
[javascript] view plain copy
49. var v="<a href=''>这是测试</a>";
50. Ext.MessageBox.alert("substr",Ext.util.Format.stripTags(v));
② 自定义校验:Ext.apply(Ext.form.VTypes, {
52. password : function(val, field) {// val指这里的文本框值,field指这个文本框组件,大家要明白这个意思
53. if (field.confirmTo) {// confirmTo是我们自定义的配置参数,一般用来保存另外的组件的id值
54. var pwd = Ext.get(field.confirmTo);// 取得confirmTo的那个id的值
55. return (val == pwd.getValue());
67. vtype : "password",// 自定义的验证类型
69. confirmTo : "pass1"// 要比较的另外一个的组件的id
name:'file',emptyText:'--请选择图片--',
@RequestMapping("/addFinancialConfirmationInformation")
@OperationDescription(type = OperationType.PAGE_INSERT, ignoreParam = false, ignoreResult = true)//定义controller方法的操作类型
public Object addFinancialConfirmationInformation(CommonsMultipartFile file,HttpServletRequest request, HttpServletResponse response, LendingConfirm lendingConfirm) {
logger.info("-----------LoanReconciliationController:addFinancialConfirmationInformation begin------------------");
String selectedData = request.getParameter("selectedData");
JSONArray jsonArray = JSONArray.fromObject(selectedData);
@SuppressWarnings({ "deprecation", "unchecked" })
List<LoanReconciliationVo> list = JSONArray.toList(jsonArray, LoanReconciliationVo.class);
Map<String, Object> map = new HashMap<String, Object>();
Date createdTime = new Date();
ExtReturn o = new ExtReturn();
// 目录命名格式如:*files2013-03-05-22
// SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
// String logoPathDir = "/upload/file" + dateformat.format(new Date());
// String logoRealPathDir = request.getSession().getServletContext().getRealPath(logoPathDir);
// File logoSaveFile = new File(logoRealPathDir);
// if (!logoSaveFile.exists()) {
// String filename = multipartFile.getOriginalFilename();
// long time = createdTime.getTime(); // 时间
// int index = filename.lastIndexOf(".");
// filename = filename + "-" + time; // 文件名
// logger.info("文件名:" + filename);
// filename = filename.substring(0, index) + "-" + time + filename.substring(index);
// logger.info("文件名:" + filename);
// String fileName = logoRealPathDir + File.separator + filename;
// lendingConfirm.setPicturePath(logoRealPathDir);
// lendingConfirm.setFileName(filename);
lendingConfirm.setFinancialStatus(1);
// File file = new File(fileName);
// multipartFile.transferTo(file);
// logger.info(filename + "上传成功!!!");
ResponseData result = loanReconciliationService.addFinancialConfirmationInformation(lendingConfirm, list);
// o.setMsg("操作成功,已导入" + list.size() + "条数据!");
// try {// 对于图片上传的formpanel,返回数据要用getwriter进行打印到页面,否则不能识别success:true
// JSONObject object = JSONObject.fromObject(o);
// response.setContentType("text/html;charset=utf-8");
// response.getWriter().print(object.toString());
logger.info("-----------LoanReconciliationController:addFinancialConfirmationInformation end------------------");
71. .x-selectable, .x-selectable * {
72. -moz-user-select: text!important ;
73. -khtml-user-select: text!important ;
75. // enable grid cell to be selected in chrome(x-selectable)/firefox(x-selectable)/IE(unselectable)
76. Ext.grid.GridView.prototype.cellTpl = new Ext.Template(Ext.grid.GridView.prototype.cellTpl.html
77. .replace('unselectable="on"', '').replace('class="',
store : new Ext.data.SimpleStore({
displayField : 'repayStateValue',
load : function(store, records, options) {
'change' : function(newV, old) {
pageQueryStore.baseParams.repayState = newV
labelStyle : "text-align:right",
proxy : new Ext.data.HttpProxy({
+ '/dict/getRepayTypes?nodeCode=HKLX'
reader : new Ext.data.JsonReader({},
css:"background-image:none;background-color:#EDEEF0;"
关于formpanel提交以后总是提示e.result错误的消息,是因为formpanel的timeout超时问题
[javascript] view plain copy
79. if (form.form.isValid()) {
82. waitMsg : '正在保存数据,请稍后...',
86. success : function(form, action) {
87. Ext.Msg.alert('保存成功', action.result.data);
90. failure : function(form, action) {
91. Ext.Msg.alert('保存失败', action.result.data);
后台返回格式为 {success:true,data:'任务提交结果!共1个.成功1 失败0 !'}
没有加 timeout 属性时,添加小任务程序没有问题,批量添加时,会发现后台已经运行完毕,但是界面卡住。
以为是后台返回的数据格式不正确,或者抛出异常导致没有提供返回值给前端,后来排除了原因,发现应该是一个超时的问题,添加后解决。
Timeout for form actions in seconds.
http://blog.youkuaiyun.com/bingyupj/article/details/8290530
if (value == null || value == 0) {
return new Date(value).format("Y-m-d H:i:s");
return Ext.util.Format.number(value, '0.0000');// 控制精度保留四位小数
if (value == null || value == 0) {
var radix=parseFloat(value).toFixed(2)+'';//保留两位小数
var thousand =radix.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');//千分位格式化
extjs EditorGridPanel禁止某些单元格编辑
[javascript] view plain copy
95. 'cellclick' : function(grid, rowIndex, columnIndex, e) {
96. var record = grid.getStore().getAt(rowIndex);
97. if(record.get('editable') == 'N' && columnIndex == 2)
需配合clicksToEdit属性,为1时修改cellclick事件,2时为celldblclick
this.gridPanel.on('afteredit', function(editor, e) {
editor.record.set('phasePlannedPrinciple', Ext.util.Format.number(
editor.record.data.phasePlannedPrinciple, '0.00')); // 设置代偿本金的保留小数是两位
editor.record.set('phasePlannedInterest', Ext.util.Format.number(
editor.record.data.phasePlannedInterest, '0.00')); // 设置代偿利息的保留小数是两位
editor.record.set('phasePlannedOverdueFine', Ext.util.Format.number(
editor.record.data.phasePlannedOverdueFine, '0.00')); // 设置代偿罚息的的保留小数是两位
editor.record.set('totalCompensation', Ext.util.Format.number(
Number(editor.record.data.phasePlannedPrinciple)
+ Number(editor.record.data.phasePlannedInterest)
+ Number(editor.record.data.phasePlannedOverdueFine),
this.gridPanel.on('beforeedit', function(editor, e, eOpts) {
DateUtils.parseStringToDate(indTime, "yyyy-MM-dd'T'HH:mm:ss");
public static Date parseStringToDate(String date, String format) {
DateFormat df = new SimpleDateFormat(format);
101.//当判断字符串时如果第二个参数不不同时结果也会不同
Ext.isEmpty(“”,true)//为tue表示允许为空
Ext.isEmpty(”“,false)//为false表示不允许为空
new Ext.grid.RowNumberer({header:'序号',width:50})
var a = new Ext.grid.ColumnModel({
columns : [e, new Ext.grid.RowNumberer({header:'序号',width:50}), {
dataIndex : "conChlShortName",
Ext.util.Format.round(value, precision);//四舍五入,precision指精确位数
一种是前端排序,不请求后台本页面列字段进行排序,在grid的列中设置属性sortable: true,
第二种排序是后台排序,请求后台对整个数据进行排序,在store中设置属性remoteSort: true,
var grid = Ext.create('Ext.grid.Panel', { title: '任务计划管理列表', region: 'center', store: store, columns: [ { header: '任务名称', sortable: true, //设置这个属性进行排序 dataIndex: 'task_name' }] });
var store = Ext.create('Ext.data.ArrayStore', { model: 'Task', autoLoad: true, pageSize: 20, // 设置服务器端映射。 proxy: { type: 'ajax', url: 'task/getTaskInfo', // 定义数据结构 reader: { type: 'json', totalProperty: 'totalProperty', root: 'root' } }, remoteSort: true //设置属性进行请求后台排序 })
json格式的名为sort的字符串里面包括两个属性一个是property是要排序的字段名,另一个是direction里面会有两个值( ASC 或DESC )我是用google的开源解析json的工具包gson来对其进行解析,代码如下:
public static Map<String,String> getSort(String sort){ Gson gson = new Gson(); Map<String,String> map = new HashMap<String,String>(); if(sort == null || "".equals(sort)){ map.put("direction",""); map.put("property", ""); }else{ List<SortData> sortData = gson.fromJson(sort, new TypeToken<List<SortData>>(){}.getType()); map.put("direction", sortData.get(0).getDirection()); map.put("property", sortData.get(0).getProperty()); } return map; }
if(sort != null){ Map<String,String> map = new HashMap<String,String>(); map = CommonUtils.getSort(sort); String property = map.get("property");//排序的字段名和前台mode中字段名一致 String direction=map.get("direction");//字符串( ASC 或DESC ) }
然后请求后台数据库进行排序,在制造的时候前台的字段名尽量和数据库的字段名保持一致,这样方便了很多东西。
一起同store请求传过来的参数还有名为start的int型参数,名为limit的int型数据,他们是分页条件,start是开始记录数,limit是本页最大记录数。