+ -
当前位置:首页 → 问答吧 → 关于Ext中JsonReader

关于Ext中JsonReader

时间:2010-09-27

来源:互联网

今天做了一个store,该store接受一个jsp返回的json,并用JsonReader读取,但无法将返回的数据读入store,求解。

Ext代码:
JScript code
Ext.onReady(function(){
 
        var _store = new Ext.data.Store({
            autoLoad:true,
            proxy:new Ext.data.HttpProxy({url:"movie.jsp"}),
                reader:new Ext.data.JsonReader({root:"info"},
                 Ext.data.Record.create([{name:"name"}]))
        });
     alert(_store.getCount());
    })


jsp代码:
Java code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%out.println("{success:true,info:[{'name':'zxy'}]}"); %>

作者: chungewudihehe   发布时间: 2010-09-27

高手帮忙

作者: chungewudihehe   发布时间: 2010-09-27

没人回答么?

作者: chungewudihehe   发布时间: 2010-09-27

格式不对,多了解一下jsonReader的格式
var myReader = new Ext.data.JsonReader({
  // metadata configuration options:
  idProperty: 'id'
  root: 'rows',
  totalProperty: 'results',
  Ext.data.DataReader.messageProperty: "msg" // The element within the response that provides a user-feedback message (optional)

  // the fields config option will internally create an Ext.data.Record
  // constructor that provides mapping for reading the record data objects
  fields: [
  // map Record's 'firstname' field to data object's key of same name
  {name: 'name'},
  // map Record's 'job' field to data object's 'occupation' key
  {name: 'job', mapping: 'occupation'}
  ]
});

This would consume a JSON data object of the form:

{
  results: 2000, // Reader's configured totalProperty
  rows: [ // Reader's configured root
  // record data objects:
  { id: 1, firstname: 'Bill', occupation: 'Gardener' },
  { id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
  ...
  ]
}

作者: zoujp_xyz   发布时间: 2010-09-27

不是格式的问题啊,我试了,还是那样。

作者: chungewudihehe   发布时间: 2010-09-27

谁给解答一下啊? 我都研究半天了

作者: chungewudihehe   发布时间: 2010-09-27