简体   繁体   中英

sending json data to a grid

I want to send the firstname mike using json to an extjs grid, that reads json.However my knowledge in Json is limited,i don't know how to create the string firstname in json and i'm failing to achieve it.Any help please on how to do so?

//java code

import java.io.*; 

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

import net.sf.json.JSON;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;


public class JsonForm extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {



    }

}


//grid

Ext.onReady(function(){
    Ext.define('Employee',{
        extend: 'Ext.data.Model',
        proxy: {
            type: 'ajax',
            reader: 'json'
        },
        fields: [{
            name: 'FirstName',
            type: 'string'
        }]
    });


    var gridStore = Ext.create('Ext.data.XmlStore', {
      model: 'Employee',
      autoLoad: true,
      proxy: {
          type: 'ajax',
          url: '',

          reader: {
              type: 'json',
              root: ''

          }
       }
   });


    grid = Ext.create('Ext.grid.Panel', { 
      store: gridStore,
      columnLines: true,
      frame: true,
      columns: [
          {text: "First Name", flex:1, dataIndex: 'FirstName', tdCls: 'no-dirty'},


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

});

I believe dataIndex value you have is not correct, you should use field's property name as the value for dataIndex.

dataIndex:'name' instead of what you have..

Take a look at this page from their docs, it might help more

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.Panel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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