gpt4 book ai didi

javascript - 将 json 发送到网格

转载 作者:行者123 更新时间:2023-12-03 08:45:55 26 4
gpt4 key购买 nike

我正在尝试将 json 数据发送到网格 extjs,但是我无法连接到网格。除了 url 之外,我的网格代码中似乎有什么问题...有什么想法吗?网格正在显示,但是语法是否正确。我知道网址丢失,但是当我添加它时,数据不会提取到网格中。

public class JsonForm extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");

PrintWriter out = response.getWriter();

JSONObject myObject = new JSONObject();
myObject.put("firstname","Mike");
myObject.put("lastname","J");
myObject.put("email","j@mail.com");
out.println(myObject);

JSONObject myRecord = new JSONObject();
myRecord.put("firstname","Mike");
myRecord.put("lastname","J");
myRecord.put("email","j@mail.com");

JSONArray myRecords = new JSONArray();
myRecords.add(myRecord);

}

}



//grid

Ext.onReady(function(){
Ext.define('myRecord',{
extend: 'Ext.data.Model',
proxy: {
type: 'memory',
reader: 'json'
},
fields: [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
'firstName','lastName', 'email'
]
});


var gridStore = Ext.create('Ext.data.JsonReader', {

autoLoad: true,
proxy: {
// load using HTTP
type: 'ajax',
url: '',
// the return will be XML, so lets set up a reader
reader: {
type: 'json',
// records will have an "Item" tag
root: 'myRecord'

}
}
});


grid = Ext.create('Ext.grid.Panel', {
store: gridStore,
// selModel: sm,
columnLines: true,
frame: true,
columns: [
{text: "First Name", flex:1, dataIndex: 'firstName', tdCls: 'no-dirty'},
{text: "Last Name", flex:1, dataIndex: 'lastName', tdCls: 'no-dirty'},
{text: "Email", flex:1, dataIndex: 'email', tdCls: 'no-dirty',}

],
renderTo:Ext.getBody(),
width: '100%',
height: 650
});

});

最佳答案

gridStore 应该是 Ext.data.Store 的实例。 Url - 应该是您的 servlet 的正确 URL。商店应包含模型:“myRecord”。根属性设置为“myRecord”,但正如我所见,您根本没有根属性。

关于javascript - 将 json 发送到网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32889813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com