-
16 Mar 2009 10:06 PM #1
datastore load error"root is undefined"
datastore load error"root is undefined"
mycode
response by firefoxCode: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} });
{"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
-
16 Mar 2009 10:11 PM #2
JSON response is wrong.
'\' remove this{"GetDepartmentListResult":"{\"TotalCount\":\"136\",\"DepartmentList\":[{\"DeptID\":37,\"DeptName\":
\"设计院\",\"DeptParent\":36,\"DeptOrder\":null,\"DeptLevel\":null,\"DeptBelong\":null},{\"DeptID\":32,
\"DeptName\":\"办领导\",\"D
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/
-
16 Mar 2009 10:38 PM #3
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; } });
-
16 Mar 2009 11:43 PM #4
code
json stringCode:DepartMentDs.load({ params: { start: 0, pagesize: 2} });
{"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
-
17 Mar 2009 12:44 AM #5
So, does your object have a property called "departMentList"?Code:root: 'DepartMentList',
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
17 Mar 2009 1:39 AM #6


Reply With Quote

