将json数据发送到网格

时间:2015-10-01 12:36:49

标签: javascript json extjs

我想使用json将名字mike发送到一个extjs网格,读取json。但是我在Json中的知识是有限的,我不知道如何在json中创建字符串firstname并且我无法实现它。请帮忙看看如何做到这一点?

//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
    });

});

1 个答案:

答案 0 :(得分:0)

我相信你拥有的dataIndex值不正确,你应该使用字段的属性名作为dataIndex的值。

dataIndex:'名称'而不是你拥有的......

从他们的文档中查看此页面,它可能会有所帮助

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

相关问题