1. #1
    Ext User
    Join Date
    Dec 2007
    Posts
    24
    Vote Rating
    0
    netbox is on a distinguished road

      0  

    Default datastore load error"root is undefined"

    datastore load error"root is undefined"


    mycode
    Code:
     var DepartMentDs = new Ext.data.Store(
            {
                proxy: new Ext.data.WCFHttpProxy({
                    url: "/OA_Service.svc/GetDepartMentList"
                }),
                reader: new Ext.data.WCFJsonReader({
                    root: 'DepartMentList',
                    totalProperty: 'TotalCount',
                    id: 'DeptID',
                    fields: [
    			{name:'DeptID',type:'int'},
    			{name:'DeptName',type:'string'},
    			{name:'DeptParent',type:'int'},
    			{name:'DeptOrder',type:'int'},
    			{name:'DeptLevel',type:'int'},
    			{name:'DeptBelong',type:'int'}
                    ]
                }),
                remoteSort: true
            }
            );
            DepartMentDs.setDefaultSort("DeptID", "asc");
    
      var cm = new Ext.grid.ColumnModel([
            rn,
            sm,
    		{header:'',dataIndex:'DeptID'},
    		{header:'部门名称',dataIndex:'DeptName'},
    		{header:'上级部门',dataIndex:'DeptParent'},
    		{header:'排序',dataIndex:'DeptOrder'},
    		{header:'层级',dataIndex:'DeptLevel'},
    		{header:'部门所属',dataIndex:'DeptBelong'},
    
    
        ]);
                    cm.defaultSortable = true;
                    var grid = new Ext.grid.GridPanel({
                        ds: DepartMentDs,
                        cm: cm,
                        sm: sm,
                        title: '通告列表',
                        bbar: new Ext.PagingToolbar({
                            pageSize: 10,
                            store: DepartMentDs,
                            displayInfo: true,
                            displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
                            emptyMsg: "没有记录"
                        }),
                        tbar: [{
                            id: 'btnAdd',
                            text: '新增',
                            tooltip: '新增',
                            iconCls: 'add',
                            handler: showAddPanel
                        }, '-', {
                            text: '修改',
                            tooltip: '修改',
                            iconCls: 'edit',
                            handler: showEditPanel
                        }, '-', {
                            text: '批量删除',
                            tooltip: '删除',
                            iconCls: 'remove',
                            handler: showDelDialog
    }]
                        });
                        this.body = grid;
    
     DepartMentDs.load({ params: { start: 0, limit: 20} });
    response by firefox

    {"GetDepartmentListResult":"{\"TotalCount\":\"136\",\"DepartmentList\":[{\"DeptID\":37,\"DeptName\":

    \"设计院\",\"DeptParent\":36,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":32,

    \"DeptName\":\"办领导\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID

    \":64,\"DeptName\":\"办领导\",\"DeptParent\":50,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null

    },{\"DeptID\":79,\"DeptName\":\"机关党委\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong

    \":null},{\"DeptID\":80,\"DeptName\":\"政秘科\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null

    ,\"DeptBelong\":null},{\"DeptID\":81,\"DeptName\":\"指通科\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel

    \":null,\"DeptBelong\":null},{\"DeptID\":82,\"DeptName\":\"工程科\",\"DeptParent\":31,\"DeptOrder\":null

    ,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":83,\"DeptName\":\"财务科\",\"DeptParent\":31,\"DeptOrder

    \":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":84,\"DeptName\":\"法制科\",\"DeptParent\":31

    ,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":85,\"DeptName\":\"指管处\",\"DeptParent

    \":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":86,\"DeptName\":\"平管处\"

    ,\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":87,\"DeptName

    \":\"重管处\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":88

    ,\"DeptName\":\"通信站\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{

    \"DeptID\":89,\"DeptName\":\"质监站\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong

    \":null},{\"DeptID\":151,\"DeptName\":\"办领导\",\"DeptParent\":150,\"DeptOrder\":null,\"DeptLevel\":null

    ,\"DeptBelong\":null},{\"DeptID\":152,\"DeptName\":\"定额站\",\"DeptParent\":36,\"DeptOrder\":null,\"DeptLevel

    \":null,\"DeptBelong\":null},{\"DeptID\":153,\"DeptName\":\"审图中心\",\"DeptParent\":36,\"DeptOrder\":null

    ,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":154,\"DeptName\":\"质检站\",\"DeptParent\":36,\"DeptOrder

    \":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":174,\"DeptName\":\"办领导\",\"DeptParent\":171

    ,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":176,\"DeptName\":\"所领导\",\"DeptParent

    \":36,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null}]}"}

    grid is empty and firebug show

    "root is undefined" at
    11936" var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;"
    here "o" has values

  2. #2
    Ext User shibubh's Avatar
    Join Date
    Jul 2007
    Location
    Lamahi,Dang Nepal
    Posts
    449
    Vote Rating
    0
    shibubh is on a distinguished road

      0  

    Default


    JSON response is wrong.
    {"GetDepartmentListResult":"{\"TotalCount\":\"136\",\"DepartmentList\":[{\"DeptID\":37,\"DeptName\":

    \"设计院\",\"DeptParent\":36,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":32,

    \"DeptName\":\"办领导\",\"D
    '\' remove this
    Shibu Bhattarai

    Use JavaScript beautifier to beautify you code http://jsbeautifier.org/

    Code Conventions http://javascript.crockford.com/code.html

    ExtJS Core Manual http://extjs.com/products/extcore/manual/

  3. #3
    Ext User
    Join Date
    Dec 2007
    Posts
    24
    Vote Rating
    0
    netbox is on a distinguished road

      0  

    Default


    Quote Originally Posted by shibubh View Post
    JSON response is wrong.

    '\' remove this


    but json string

    {"GetContactsListResult":"{\"TotalCount\":\"6\",\"ContactsList\":[{\"ContactID\":1,\"ContactType\":\"22

    \",\"ContactName\":\"\",\"ContactClass\":\"111\"},{\"ContactID\":2,\"ContactType\":\"私有\",\"ContactName

    \":\"fsdf\",\"ContactClass\":\"111\"},{\"ContactID\":3,\"ContactType\":\"公有\",\"ContactName\":\"dasd

    \",\"ContactClass\":\"111\"},{\"ContactID\":4,\"ContactType\":\"私有\",\"ContactName\":\"\",\"ContactClass

    \":\"111\"},{\"ContactID\":5,\"ContactType\":\"私有\",\"ContactName\":\"\",\"ContactClass\":\"111\"},{

    \"ContactID\":6,\"ContactType\":\"dfs\",\"ContactName\":\"ff\",\"ContactClass\":\"222\"}]}"}

    work fine at another grid, and total 10 grid only department grid show this error. mycode is generate by codesmith,json string is from WCF,my wcfjsonreader

    Code:
    /**   
    * @class Ext.data.WCFJsonReader  
    * @extends Ext.data.JsonReader 
    * 
    * Custom reader for reading data from WCF.  If you are using WebMessageBodyStyle.Wrapped, then WCF adds a root object to your   
    * JSON result: 
    *    
    * { "MethodResult": { "Count" : 0, "Objects": [ … ] } }   
    *  
    * Ext does not expect the result to have a root object before parsing, so this class will remove it.    
    */
    Ext.data.WCFJsonReader = Ext.extend(Ext.data.JsonReader, {
        /* @cfg {Boolean} Sets whether or not the OperationContract has the is using WebMessageBodyStyle.Wrapped */
        wrapped: true,
        /**  
        * If wrapped is set to true, we will strip WCF’s wrap object    
        */
        read: function(response) {
            var json = response.responseText;
            var o = eval("(" + json + ")");
            if (!o) {
                throw { message: "JsonReader.read: Json object not found" };
            }
            if (this.wrapped) {
                for (var prop in o) {
                    if (typeof (prop) == 'string' && prop.substr(prop.length - 6, prop.length) == 'Result') {
                        o = this.convert(o[prop]);
                        //o = o[prop]; 
                        break;
                    }
                }
            }
            if (o.metaData) {
                delete this.ef;
                this.meta = o.metaData;
                this.recordType = Ext.data.Record.create(o.metaData.fields);
                this.onMetaChange(this.meta, this.recordType, o);
            }
            return Ext.data.WCFJsonReader.superclass.readRecords.call(this, o);
        },
        //private   
        convert: function(o) {
            o = eval("(" + o + ")");
            var newResult = new Object();
            for (var rootProp in o) {
                newResult[rootProp] = o[rootProp];
            }
            return newResult;
        }
    });

  4. #4
    Ext User
    Join Date
    Dec 2007
    Posts
    24
    Vote Rating
    0
    netbox is on a distinguished road

      0  

    Default


    code

    Code:
    DepartMentDs.load({ params: { start: 0, pagesize: 2} });
    json string

    {"GetDepartmentListResult":"{\"TotalCount\":\"136\",\"DepartmentList\":[{\"DeptID\":32,\"DeptName\":

    \"办领导\",\"DeptParent\":31,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":37,

    \"DeptName\":\"设计院\",\"DeptParent\":36,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null}]}"

    }
    attachments "111.jpg" is firebug print screen
    Attached Images

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Code:
    root: 'DepartMentList',
    So, does your object have a property called "departMentList"?

  6. #6
    Ext User
    Join Date
    Dec 2007
    Posts
    24
    Vote Rating
    0
    netbox is on a distinguished road

      0  

    Default


    thank you very much:)

Thread Participants: 2