简体   繁体   English

将JSON发送到网格

[英]Sending json to a grid

I'm trying to send json data to a grid extjs, however i'm failing to connect to the grid.Besides the url what seems to be wrong in my grid code...Any ideas?The grid is displaying but is the syntax correct.I know the url is missing, but when i add it, the data isn't extracted to the grid. 我正在尝试将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
    });

});

The gridStore should be the instance of Ext.data.Store. gridStore应该是Ext.data.Store的实例。 Url - should be proper url to your servlet. 网址-应该是您的servlet的正确网址。 Store should contain model: 'myRecord'. 商店应包含模型:“ myRecord”。 Root property is set to 'myRecord', but as I can see you don't have root property at all. 根属性设置为“ myRecord”,但是正如我所看到的,您根本没有根属性。

Is your servlet code executed? 您的Servlet代码是否已执行? If it is, take a look to the response you receive from your servlet. 如果是这样,请查看您从Servlet收到的响应。 Probably json response is not correctly formed. 可能是json响应格式不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM