ps: 在 renderer 中使用 Ajax 访问服务器, 并不是一个很好的方法因为会徒增大量的页面负载, 个人建议是将数据在后台处理好后, 封装到 store 中.
以下是在 renderer 中利用 Ajax 渲染表格内容的代码:
- // 定义列模式
- var colunms=[
- { header: '项目名称', align: 'left', dataIndex : 'xm_name', flex: 1, sortable: false},
- { header: '项目类型', align: 'left', dataIndex : 'itemType', flex: 1, sortable: false,renderer:function(value){
- return getDicNameByDicId(value);
- }},
- { header: '项目类别', align: 'left', dataIndex : 'itemCategory', flex: 1, sortable: false,renderer:function(value){
- return getDicNameByDicId(value);
- }},
- { header: '重要程度', align: 'left', dataIndex : 'importantDegree', flex: 1, sortable: false,renderer:function(value){
- return getDicNameByDicId(value);
- }},
- { header: '申报年度', align: 'left', dataIndex : 'inputYear', flex: 1, sortable: false},
- { header: '实施年度', align: 'left', dataIndex : 'forYear', flex: 1, sortable: false},
- { header: '项目年度', align: 'left', dataIndex : 'theyear', flex: 1, sortable: false}
- ];
渲染的方法. 这里的需求是根据单元格的 id 值从数据库获取对应的 name.
- function getDicNameByDicId(datas){
- var name ="";
- Ext.Ajax.request({
- url: contextPath + "/FtProjectAction!getDicNameByDicId.action",
- params: {datas:datas},
- async:false,
- success: function (response, opts) {
- var jsonData= Ext.JSON.decode(response.responseText);
- name=jsonData.msg;
- },
- failure: function (response, opts) {
- }
- });
- return name;
- }
async:false 是必须设置的 不然浏览器在返回值之前已经渲染了页面. 导致单元格内容不显示.
async 设置为 false, 则所有的请求均为同步请求, 在没有返回值之前, 同步请求将锁住浏览器, 用户其它操作必须等待请求完成才可以执行.
来源: http://www.bubuko.com/infodetail-2799191.html