1.利用AJAX加载的数据封装到store中
项目开发遇见的问题。
将ajax检索的结果加入到store中去
代码片
1.ajax
var t = Ext.getCmp("title_cn").value;
Ext.Ajax.request({
url : "./system/flfgzyk/flfg/solrquery.action",
method : "post",
params:{
t:t
},
success : function(response, opts){
//从后台获取json数据,进行解析
var data = Ext.decode(response.responseText);
//找到定位加载页面
var grid=Ext.getCmp("gnxh341id");
//数据放入store里面加载 信息
grid.store.loadData(data.jsonarray);
},
failure: function(response, opts) {
Ext.Msg.alert('系统提示',"查询失败!请与管理员联系");
}
});
2.store
var pageSize = 100;
Ext.define("fgql.xxfggl.store.xxfgglStore",{
extend:"Ext.data.Store",
model:"fgql.xxfggl.model.xxfgglModel",
pageSize:pageSize,
proxy:{
type:"ajax",
api:{
read:"/LFZXXT/system/fgql/xxfggl/getxxfgglcount.action"
},
reader:{
type:"json",
root:"jsonarray",
totalProperty:"total"
}
},
autoLoad:false
});
3.model
Ext.define("fgql.xxfggl.model.xxfgglModel",{
extend:"Ext.data.Model",
fields:[
'title_cn',//中文标题
'title_en',//英文标题
'law_id',//序号
'fbbm_name',//发布部门编号
]
});
Ext.define("flfgzyk.flfg.view.flfgGridPanel",{
extend:"Ext.grid.Panel",
alias:"widget.gnxh341",
id:"gnxh341id",
// store: "zjlx.zjrkgl.store.zjrkglStore",
store: "flfgzyk.flfg.store.flfgStore",
forceFit:true,
loadMask:true,
columnLines:true,
autoScroll:true,
requires: [
'common.util.search.SearchButton',//检索按钮
'common.util.search.Query',//检索类型
],
columns:[
{header:"序号",xtype:"rownumberer",flex:0.5,align:"center",sortable:false,tdCls:"gridheight"},
{header:"中文标题",dataIndex:"title_cn",flex:2,align : "center",sortable : true,tdCls : "gridheight"},
{header:"英文标题",dataIndex:"title_en",flex:2,align : "center",sortable : true,tdCls : "gridheight",},
{header:"发布部门",dataIndex:"fbbm_name",flex:1,align : "center",sortable : true,tdCls : "gridheight"},
{header:"发布字号",dataIndex:"fbzh",flex:1,align : "center",sortable : true,tdCls : "gridheight"},
{header:"发布日期",dataIndex:"fbrq",flex:1,align : "center",sortable : true,tdCls : "gridheight"},
{header:"实施日期",dataIndex:"ssrq",flex:1,align : "center",sortable : true,tdCls : "gridheight"},
{header:"时效性",dataIndex:"sxx_name",flex:1,align : "center",sortable : true,tdCls : "gridheight"},
{header:"查看",xtype:"actioncolumn",flex:1,align:"center",sortable:false,tdCls:"gridheight",
items:[
{
xtype:"actioncolumn",
iconCls:"grid_search",
tooltip:"专家入库推荐查看",
handler:function(grid, rowIndex, colIndex) {
var type_links=grid.getStore().getAt(rowIndex).get('law_content_url')
window.open("/LFZXXT/system/flfgzyk/flfg/QtzmclCK.action?" +//打印
"pdflj="+type_links);
}
},
]
},
],
dockedItems:[
{
xtype:'toolbar',
dock:'top',
items:[
{
xtype:'displayfield',value:'',id:'welcomeDwXx'
},
'->',
{
xtype:'label',
html:'<font color=black size=5px><b>法律法规</b></font>',
},
'->',
{xtype:'container',
items:[
{
xtype:"button",
text:"返回上级",
handler:function() {
location.href='/LFZXXT/system/yhdl.jsp';
}
}
]
}
]
},
{
xtype:'toolbar',
dock:'top',
items:[
"->",
{xtype:'textfield',name:'title_cn',id:'title_cn',fieldLabel:'<font color="blue">法律法规</font>',labelWidth:60,emptyText:'请输入',search: true,searchtype: 'like'},
{xtype:'container',
items:[
{
id : 'image_button2',
xtype : 'button',
iconCls:"grid_search",
tooltip:"检索",
text : '检索',
listeners:{
click:function(){
var t = Ext.getCmp("title_cn").value;
Ext.Ajax.request({
url : "./system/flfgzyk/flfg/solrquery.action",
method : "post",
params:{
t:t
},
success : function(response, opts){
//从后台获取json数据,进行解析
var data = Ext.decode(response.responseText);
//找到定位加载页面
var grid=Ext.getCmp("gnxh341id");
//数据放入store里面加载 信息
grid.store.loadData(data.jsonarray);
console.log(data.jsonarray)
},
failure: function(response, opts) {
Ext.Msg.alert('系统提示',"保存失败!请与管理员联系");
}
});
}
}
}
]
}
]
}
],
listeners:{
'beforerender':function(me){
var store1=Ext.getCmp("gnxh341id").getStore()
store1.load();
}}
});