首页新闻找找看学习计划

ExtJs Grid 从后台获取的json数据显示不出来,希望大神能帮忙看看,谢谢了,初次接触

0
悬赏园豆:10 [待解决问题]

代码如下:

var prox = new Ext.data.HttpProxy({ url: "windows/aaa.aspx" });
var read = new Ext.data.JsonReader({
  root: 'data',
  totalProperty: 'total',
  fields: [
    { name: 'id', type: 'string' },
    { name: 'name', type: 'string' },
    { name: 'salary', type: 'string' },
    { name: 'createDate', type: 'string' }
  ],

   remoteSort: true
});


var store = new Ext.data.JsonStore({
  ///远程数据代理
  proxy: prox,
  ///从数据代理中读取数据
  reader: read,
  autoLoad: true,//自动加载
  pageSize: 15
});

var grid = Ext.create("Ext.grid.Panel", {
  border: false,
  xtype: 'grid',
  width: (window.screen.width - 10),
  height: '100%',
  store: store,
  columnLines: true,
  forceFit:true,
  //loadMask: true,
  selModel: Ext.create("Ext.selection.CheckboxModel", {
    injectCheckbox: 0,//checkbox位于哪一列,默认值为0
    mode: "simple",//multi,simple,single;默认为多选multi
    checkOnly: false,//如果值为true,则只用点击checkbox列才能选中此条记录
    allowDeselect: true,//如果值true,并且mode值为单选(single)时,可以通过点击checkbox取消对其的选择
    enableKeyNav: true
  }),
  columns: [
    { header: "id", width: 60, dataIndex: 'id', sortable: true },
    { header: "name", width: 60, dataIndex: 'name', sortable: true },
    { header: "salary", width: 60, dataIndex: 'salary', sortable: true },
    { header: "createDate", width: 100, dataIndex: 'createDate' }
  ],
  dockedItems: [{
    xtype: 'toolbar',
    dock: 'top',
    items: [tbar0]
  }, {
    xtype: 'toolbar',
    dock: 'top',
    items: [tbar1]
  }],

  bbar: Ext.create('Ext.PagingToolbar', {
    id: 'pagingBT',
    store: store,
    displayInfo: true,
    displayMsg: '显示 第 {0} - {1} 条记录 一共 {2} 条记录',
    emptyMsg: "没有记录"
  })
});

但是运行后

金同学的主页 金同学 | 初学一级 | 园豆:65
提问于:2017-06-20 16:26
< >
分享
所有回答(4)
0

F12看看console

默卿 | 园豆:4063 (老鸟四级) | 2017-06-20 16:59

什么都没有,没有错误,很奇怪,我用本地的测试json格式数据就可以,从服务器请求的数据就不行,本地的测试数据就是从服务器复制的json格式数据

支持(0) 反对(0) 金同学 | 园豆:65 (初学一级) | 2017-06-20 17:03

@金同学: 可能和请求有关系 看是不是请求跨域了没得到数据

支持(0) 反对(0) 默卿 | 园豆:4063 (老鸟四级) | 2017-06-20 17:22

@冷星淡月: 怎么看

支持(0) 反对(0) 金同学 | 园豆:65 (初学一级) | 2017-06-20 17:38
0

确定后台传过来的数据已经转化为JSON格式了?前台把你传过来的数据显示出来看看吧

姚刘乐 | 园豆:70 (初学一级) | 2017-06-21 09:52

{"total":50,"data":[{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"},{"id":"1","name":"1","salary":"2008-03-14","createDate":"22:43:09"}]}

支持(0) 反对(0) 金同学 | 园豆:65 (初学一级) | 2017-06-21 09:59
0

salary":"2008-03-14","createDate":"22:43:09" 请你大声地告诉我这些都是什么类型?记得不错的话 salary不是薪水的意思吗?为什么对应的值是类时间类型。

~扎克伯格 | 园豆:1797 (小虾三级) | 2017-06-21 12:19

这个只是随意的测试数据,放在本地可以出来列表,从服务器获取的就没有出来列表,不知道为什么,困扰了三天了

支持(0) 反对(0) 金同学 | 园豆:65 (初学一级) | 2017-06-21 12:53
0

谢谢各位的回答了,终于弄好了,原来ext 4.2开始要定义模型了

//1.定义Model
Ext.define("MyApp.model.User", {
extend: "Ext.data.Model",
fields: [
{ name: 'id', type: 'int' },
{ name: 'yhm', type: 'string' },
{ name: 'zh', type: 'string' },
{ name: 'gsid', type: 'int' },
{ name: 'ssgsmc', type: 'string' },
{ name: 'bmid', type: 'int' },
{ name: 'ssbmmc', type: 'string' },
{ name: 'gzdh', type: 'string' },
{ name: 'sjhm', type: 'string' },
{ name: 'yx', type: 'string' },
{ name: 'ygbh', type: 'string' },
{ name: 'fwfwtext', type: 'string' }
]
});

var prox = new Ext.data.HttpProxy({//grid绑定数据源
url: "Data.axd",
type: "ajax",
successProperty: true,
actionMethods: { read: 'POST' },
extraParams: {
className: "Tab_Jin_Users_Service",
methodName: "SelectAllUsers",
methodParams: param
},
reader: {
root: "data",
totalProperty: 'total'
}
});

var store = new Ext.data.Store({
///远程数据代理
proxy: prox,
model: "MyApp.model.User",
autoLoad: false,
pageSize: 15,
});

金同学 | 园豆:65 (初学一级) | 2017-06-23 12:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册