ExtjsMVC开发过程中遇到的具体问题总结

时间:2023-03-09 00:02:30
ExtjsMVC开发过程中遇到的具体问题总结

1.登陆相关问题

1.如何在文本框中增加提示信息
             2.如何在文本框中触发回车事件
             3.如何在回车事件中触发按钮的动作
             总结:http://www.cnblogs.com/sdjnzqr/p/3922726.html

2.只读文本框样式设置

参考文章:http://*.com/questions/9214297/how-do-i-change-color-of-a-textfield-using-extjs

3.关于查询数据返回的问题

在真正的业务系统中,大部分数据返回时无法返回数据库中对应的实体,一般来说都是几个实体之间的混合属性,这就造成了如果使用MVC架构时,需要在做查询时,创建大量的Model,造成代码的复杂度,因此建议尽量少用Model,有可能的话尽量使用json。

4.Ajax调用的方式

http://blog.csdn.net/hrl_100/article/details/5639922
 
5.全局变量的使用
 
 参考:http://phpcode8.com/web/extjs/extjs-global-variable.html
 
6.form提交时返回的json格式

would process the following server response for a successful submission:
{
"success":true, // note this is Boolean, not string
"msg":"Consignment updated"
}

and the following server response for a failed submission:

{
"success":false, // note this is Boolean, not string
"msg":"You do not have permission to perform this operation"
}
 
7.SpringMVC返回中文String时出现中文乱码
  
   第一种解决方案:
@RequestMapping(value="/sys/functiontree",produces="text/plain;charset=UTF-8")
@ResponseBody
public String getTreeData()

第二种解决方案:通过修改XMl配置文件或者而修改源码来实现。

参考文章:

http://www.oschina.net/question/105887_114629?sort=time

http://blog.csdn.net/kissliux/article/details/14053761

注意:

我使用的是3.1.2的Spring包,在3.1.2版本中通过配置XML无法解决,只能通过修改源码或者继承类的方式实现。

另外:每个版本的StringHttpMessageConverter的实现方式不一样,注意实现方式。

 
 
7.树的相关问题
  参考文章:
     http://www.cnblogs.com/mrye/archive/2013/05/26/3100431.html
     http://ishowshao.com/blog/2012/08/17/extjs-4-trees/
注意事项:
   1.数的来源依赖于Ext.data.TreeStore,所以一定要定好这个数据源。
   2.定义树节点属性时,一定要的定义的是Id,text,leaf,如果要使用其他的字段来代替,比如想通过name来作为树节点的现实内容,则需要通过column来定义。
 
8.Controller中refs属性的理解
 
参考文章:
    http://www.cnblogs.com/liuqxFuture/archive/2012/11/10/2763764.html
    http://czpae86.iteye.com/blog/1181110
 
9.动态加载controller的问题****重点
 
参考文章:http://www.cnblogs.com/servant/archive/2013/04/01/ExtJs4mvc%E5%8A%A8%E6%80%81%E5%8A%A0%E8%BD%BDController.html
注意事项:
   原文中:
    var bhcmsController = application.getController('BHCMSController');
bhcmsController.init(self);
会造成在init方法执行两次会有问题,正确的应该是:
if(!Ext.ClassManager.isCreated('MyExt.controller.qxgl.UserController')){//判断controller是否已经加载;
Ext.require("MyExt.controller.qxgl.UserController", function () {
var userController = app.getController('qxgl.UserController');
app.getController('FirstPageController').addTab(record.get('id'),record.get('text'),'qxgl_userlist','true');
}, self);
}else{
app.getController('FirstPageController').addTab(record.get('id'),record.get('text'),'qxgl_userlist','true');
}
 
 
 
10.Form布局定义的问题
 
参考文章:http://z-xiaofei168.iteye.com/blog/1136291
 
11.关闭tab页报错的问题
 
错误描述:Error: Cannot read property 'addCls' of null
 
原因:http://blog.csdn.net/lc448986375/article/details/8019649
 
12.如何刷新grid的问题
 
http://blog.csdn.net/lc448986375/article/details/8019649
 
13.grid日期列显示的问题
 
通过renderer属性来将后台传过来的数字时间变成Extjs能够接受的时间
            text : '登陆时间',
dataIndex : 'lastLogin',
renderer: function(value){
return Ext.util.Format.date(new Date(1404098883000),'Y-m-d');
}
 

14.DataGird分页的实现

参考文章:http://www.vipaq.com/Article/View/blog/239.html

后台实现时必须的三个参数:page,start,limit

代码实现:

var store = Ext.create('Ext.data.Store', {
id:'simpsonsStore',
autoLoad: false,
fields:[
{ name: 'id', type: 'string' },
{ name: 'userCode', type: 'string' },
{ name: 'loginState', type: 'string' },
{ name: 'lastLogin', type: 'string' },
],
pageSize: 10, // items per page
proxy: {
type: 'ajax',
url: 'test/queryAllUsers.json', // url that will load data with respect to start and limit params
reader: {
type: 'json',
root: 'rows',
totalProperty: 'total'
}
}
});
Ext.create('Ext.grid.Panel', {
title : '查询结果',
region : 'center',
margin : '5 0 0 0',
store: store,
columns : [ {
text : '用户ID',
dataIndex : 'id'
}, {
text : '用户编码',
dataIndex : 'userCode',
flex : 1
}, {
text : '登陆状态',
dataIndex : 'loginState'
}, {
text : '登陆时间',
dataIndex : 'lastLogin',
renderer: function(value){
return Ext.util.Format.date(new Date(1404098883000),'Y-m-d');
}
} ],
dockedItems: [{
xtype: 'pagingtoolbar',
store: store, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
})
//带参数查询
store.on("beforeload",function(){
Ext.apply(store.proxy.extraParams, {userid:button.up('form').down('textfield[name=id]').getValue(),
usercode:button.up('form').down('textfield[name=usercode]').getValue()});
});
//datagrid查询
store.load({
params:{
start:0,
limit: 10,
}
});