1. #1
    Ext User cyclops's Avatar
    Join Date
    Dec 2009
    Posts
    12
    Vote Rating
    0
    cyclops is on a distinguished road

      0  

    Question 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:

    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'
            }
        });
    That's what my Loader Page returns:

    Code:
    [{"id":"1","cls":"folder","leaf":false,"text":"Hallo"},{"id":"2","cls":"folder","leaf":false,"text":"Selber Hallo"}]
    The returned content type is: application/json; charset=utf-8 (but neither text/html nor a different charset make any difference).

    My ashx-file is declared as follows (just the essentials):

    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));
            }
    (ExtJsTreeNode is one of my own helper classes, merely a struct).

    Maybe I'm missing something really basic - hope you've got an idea.

    Regards
    Markus

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    83
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Are you sure that this is the exact response from your server?

  3. #3
    Ext User cyclops's Avatar
    Join Date
    Dec 2009
    Posts
    12
    Vote Rating
    0
    cyclops is on a distinguished road

      0  

    Default


    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) - ???

  4. #4
    Ext User cyclops's Avatar
    Join Date
    Dec 2009
    Posts
    12
    Vote Rating
    0
    cyclops is on a distinguished road

      0  

    Lightbulb (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.

    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);
            }
        }
    });
    Maybe you've got an idea where to start to find out what the real problem is?

  5. #5
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    83
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    eval() and Ext.decode() are exactly the same (unless you set Ext.USE_NATIVE_JSON=true).

  6. #6
    Ext User cyclops's Avatar
    Join Date
    Dec 2009
    Posts
    12
    Vote Rating
    0
    cyclops is on a distinguished road

      0  

    Lightbulb 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

  1. Treepanel with "nodedragover" and "beforeremove" events problems
    By Maxrunner in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 12 Apr 2010, 6:25 AM
  2. TreePanel loader with "post" method ?
    By stevanovich in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 9 Dec 2008, 2:35 PM
  3. "Package" output directory - need input please
    By jack.slocum in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 27 Feb 2007, 1:50 PM

Thread Participants: 1

Tags for this Thread