这是我的 ExtJS 代码,用于在网格中显示我的记录。
var remoteProxy = new Ext.data.ScriptTagProxy({
url : 'hastanebilgilerinigetir'
});
var recordFields = [
{ name : 'hid', mapping : 'hid'},
{ name : 'isim', mapping : 'isim'},
{ name : 'adres', mapping : 'adres'},
{ name : 'telefon', mapping : 'telefon'},
{ name : 'bashekimid', mapping : 'bashekimid' }
];
var remoteJsonStore = new Ext.data.JsonStore({
proxy : remoteProxy,
storeId : 'ourRemoteStore',
root : 'records',
autoLoad : false,
//totalProperty : 'totalCount',
remoteSort : true,
fields : recordFields,
idProperty : 'hid'
});
var textFieldEditor = new Ext.form.TextField();
var numberFieldEditor = {
xtype : 'numberfield',
minLength : 5,
maxLength : 5
};
var columnModel = [
{
header : 'Hastane Adı',
dataIndex : 'isim',
sortable : true,
editor : textFieldEditor
},
{
header : 'Telefon',
dataIndex : 'telefon',
sortable : true,
editor : textFieldEditor
},
{
header : 'Adres',
dataIndex : 'adres',
sortable : true,
editor : textFieldEditor
},
{
header : 'Baş Hekim ID',
dataIndex : 'bashekimid',
sortable : true,
editor : numberFieldEditor
},
{
header : 'Hastane ID',
dataIndex : 'hid',
sortable : true,
editor : numberFieldEditor
}
];
var grid = {
xtype : 'editorgrid',
columns : columnModel,
id : 'myEditorGrid',
store : remoteJsonStore,
loadMask : true,
bbar : pagingToolbar,
stripeRows : true,
viewConfig : {
forceFit : true
},
listeners : {
cellcontextmenu : doCellCtxMenu,
destroy : function(thisGrid) {
if (thisGrid.rowCtxMenu) {
thisGrid.rowCtxMenu.destroy();
}
}
}
};
var hastanegridi = new Ext.Panel({
title: 'Hastaneler',
height : 700,
width : 950,
border : false,
layout : 'fit',
items : grid
});
remoteJsonStore.load({
params : {
start : 0,
limit : 50
}
});
我有以下 java 代码来创建 JSONObject
@Override
public JSONObject listHastanesAsJson() {
List<Hastane> lst = hastaneDao.listHastane();
JSONArray arr = new JSONArray();
// int i=lst.size();
// JSONObject counter = new JSONObject();
// counter.put("totalCount", i);
// arr.add(counter);
for(Hastane kan:lst){
JSONObject obj = new JSONObject();
obj.put("hid", kan.getHid());
obj.put("isim", kan.getIsim());
obj.put("adres", kan.getAdres());
obj.put("telefon", kan.getTelefon());
obj.put("bashekimid", kan.getBahekimid());
arr.add(obj);
}
JSONObject o = new JSONObject();
o.put("records", arr);
return o;
}
我的 Json 数据如下所示:
{"records":[{"hid":1,"isim":"Zeynep Kamil","adres":"Istanbul","telefon":"056765434567","bashekimid":1},{"hid":2,"isim":"Ankara Hastanesi","adres":"Ankara","telefon":"345678987658","bashekimid":2},{"hid":3,"isim":"Baskent Hastanesi","adres":"Ankara","telefon":"567898765697","bashekimid":3}]}
但是当我尝试在浏览器中显示我的数据时,出现“无效标签”下方的错误
在服务器端创建 JSONObject 时是否有错误?
我的 json 数据必须类似于此链接,但我不知道如何构建我的数据,如下所示:http ://extjsinaction.com/dataQuery.php