【发布时间】:2011-11-11 10:43:22
【问题描述】:
请在下面提到的情况下帮助我;
我的 Java Web 应用程序使用 JSON 作为数据交换格式。在跑步的时候; firebug(firefox) 按预期显示响应和 JSON 数据;但网格没有按预期更新,而是空白。下面是 store 和 grid 的定义;
//Grid & Store definition
var searchResultStore = Ext.create('Ext.data.JsonStore', {
model : 'BookModel',
proxy : {
type : 'ajax',
reader : {
totalProperty : 'results',
type : 'json',
root : 'data'
}
},
autoLoad : true
});
Ext.define('Library.SearchBookGrid', {
extend : 'Ext.grid.Panel',
alias : 'widget.SearchBookGrid',
id : 'searchBookGrid',
title : 'Books',
closable : true,
initComponent : function() {
this.store = searchResultStore;
this.columns = [ {
xtype : 'gridcolumn',
dataIndex : 'title',
text : 'Title'
}, {
xtype : 'gridcolumn',
dataIndex : 'authorName',
text : 'Author'
} ];
this.callParent(arguments);
}
});
有一个BOOK SEARCH ExtJS表单;它调用 URL (/MyLibrary/Books?action=6) & 搜索表单值作为 JSONDATA 提交。将搜索结果分配给以下商店(searchResultStore);
Ext.Ajax.request({
url : '/MyLibrary/Books?action=6',
headers: {'Content-Type':'application/json; charset=utf-8'},
jsonData : Ext.JSON.encode(form.getValues()),
params:{
action : 6
},
method : 'POST',
success : function(response, request) {
searchResultStore.loadData(Ext.JSON.decode(response.responseText));
},
failure : function(results, request) {
Ext.Msg.alert("Search..", "Please try again...!!");
},
});
我是否遗漏了什么或者我在这段代码中有错误......请帮助......!!!!
提前谢谢...!!
【问题讨论】:
-
读取器仅用于存储加载 ajax 请求,因此对于您自己的 ajax 请求,数据应该是一个元素数组。不在根数据属性内,也许这可能是你的问题
-
感谢您的回复 nscrob;你的意思是说...响应文本应该是 JSONArray 而不是 JSONObject...请纠正我...!!