-
23 Jun 2010 1:06 AM #1
TreePanel "chops" output from .Net Loader
TreePanel "chops" output from .Net Loader
Back to the old "Trees suck but I've got to use them" issue...
I'm trying to load nodes from a .Net WebHander Page (ashx) but the tree displays each individual character of my output as folder (in Fifo 3.6.3, IE 8 doesn't render any children). Still the output seems to be correct as Firebug shows the array in it's JSON view as expected.
Here's my tree config:
That's what my Loader Page returns:Code:var treePanel = new Ext.tree.TreePanel({ width: 450, region: 'west', useArrows: true, autoScroll: true, enableDD: false, id: 'document_tree', containerScroll: true, border: false, dataUrl: 'GetTemplateTree.ashx', rootVisible: false, root: { nodeType: 'async', text: 'Dokumente', cls: 'folder', id: '0' } });
The returned content type is: application/json; charset=utf-8 (but neither text/html nor a different charset make any difference).Code:[{"id":"1","cls":"folder","leaf":false,"text":"Hallo"},{"id":"2","cls":"folder","leaf":false,"text":"Selber Hallo"}]
My ashx-file is declared as follows (just the essentials):
(ExtJsTreeNode is one of my own helper classes, merely a struct).Code:public void ProcessRequest(HttpContext context) { var tree = new List<ExtJsTreeNode> { new ExtJsTreeNode {text = "Hallo", id = "1", cls = "folder", leaf = false}, new ExtJsTreeNode {text = "Selber Hallo", id = "2", cls = "folder", leaf = false} }; context.Response.ContentType = "application/json"; var serializer = new JavaScriptSerializer(); context.Response.Write(serializer.Serialize(tree)); }
Maybe I'm missing something really basic - hope you've got an idea.
Regards
Markus
-
23 Jun 2010 1:34 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Are you sure that this is the exact response from your server?
-
23 Jun 2010 2:49 AM #3
Well that's what I copied from firebug...
I just tested this on a "real" webserver running IIS 6.0 and it works fine - seems this is only an issue to my local test (IIS 5.1) and development (ASP.NET Development Server/9.0.0.0) - ???
-
23 Jun 2010 4:58 AM #4
(almost) solved...
(almost) solved...
I eventually solved this by subclassing the TreeLoader and using simple eval instead of Ext.decode, I will continue to investigate this but for now it solved my problem.
Maybe you've got an idea where to start to find out what the real problem is?Code://tree loader for consumption of ashx output Ext.namespace('Ext.qs.tree'); Ext.qs.tree.AshxLoader = function(config) { //Calls our super-class (Ext.data.DataProxy) constructor for full initialization Ext.qs.tree.AshxLoader.superclass.constructor.call(this, config); }; Ext.extend(Ext.qs.tree.AshxLoader, Ext.tree.TreeLoader, { processResponse: function(response, node, callback, scope) { var json = response.responseText; try { //this is the original line //var o = response.responseData || Ext.decode(json); var o = eval(json); node.beginUpdate(); for (var i = 0, len = o.length; i < len; i++) { var n = this.createNode(o[i]); if (n) { node.appendChild(n); } } node.endUpdate(); this.runCallback(callback, scope || node, [node]); } catch (e) { this.handleFailure(response); } } });
-
23 Jun 2010 5:01 AM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
eval() and Ext.decode() are exactly the same (unless you set Ext.USE_NATIVE_JSON=true).
-
23 Jun 2010 5:48 AM #6
Solved (finally)!
Solved (finally)!
Indeed they are. Checking further I remembered using a script that overrides Ext.decode (Ryan Moore's datefix) to handle the unusual dateformat of DotNet-Webservices (hasn't been solved any other way, er?). It just didn't take into account JSON strings may start with square brackets as well as curly ones. After changing this in the datefix script everythings working fine again - sorry for wasting your time
Code:this.decode = function(json) { var obj = json; var type = typeof json; //Application.log(type + ' ' + json); if (type == 'string') { //original line //if (json.indexOf('{') == 0) { if (json.indexOf('{') == 0 || json.indexOf('[') == 0) { return eval('(' + json + ')'); } else { return eval('(\'' + json + '\')'); } } }; })();
Similar Threads
-
Treepanel with "nodedragover" and "beforeremove" events problems
By Maxrunner in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 12 Apr 2010, 6:25 AM -
TreePanel loader with "post" method ?
By stevanovich in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 9 Dec 2008, 2:35 PM -
"Package" output directory - need input please
By jack.slocum in forum Ext 2.x: Help & DiscussionReplies: 8Last Post: 27 Feb 2007, 1:50 PM


Reply With Quote