Callback on initAjax success

1,565 views
Skip to first unread message

psaf...@googlemail.com

unread,
Aug 5, 2013, 12:11:06 PM8/5/13
to dyna...@googlegroups.com
Can I set a callback on the initialisation of the tree from Ajax? With access to the full object passed from the Ajax call? I tried this:

    $("#tree").dynatree({
        title: "File Browser",
        fx: { height: "toggle", duration: 200 },
        autoFocus: false, 
        initAjax: {
            url: "../cgi-bin/getchildren.py?nodeid=0",
            data: { mode: "funnyMode" },
            success : function(node){
                alert(node.data.totalsize);
            }
        },

but the alert didn't fire on init.

This worked for lazy-loading after the first load, though:

        onLazyRead: function(node){
            node.appendAjax({
                url: "../cgi-bin/getchildren.py",
                data: {nodeid: node.data.key,
                       mode: "funnyMode"
                         },
                success : function(node){
                    alert(node.data.totalsize);
                }
            });
             

Peter

psaf...@googlemail.com

unread,
Aug 6, 2013, 4:36:20 AM8/6/13
to dyna...@googlegroups.com, psaf...@googlemail.com
OK, I've seen the error message in the console now, which tells me to use onPostInit instead. The trouble is that onPostInit does not seem to give me access to the object returned by the Ajax call. I want this so I can pass back a lot of other metadata from the Ajax call and use it in my page, even if Dynatree is ignoring those fields. How do I do this?

Peter

mar10

unread,
Aug 7, 2013, 1:09:04 PM8/7/13
to dyna...@googlegroups.com, psaf...@googlemail.com
a better approach might be to implement the 'postProcess' callback option.

Vic...@caseparts.com

unread,
Aug 7, 2013, 1:19:02 PM8/7/13
to dyna...@googlegroups.com, psaf...@googlemail.com
Mark,

I've implemented the post process but it doesn't seem to fire.  Like the previous comment, I tried using the onPostInit and did not have access to the object.

Here is my code, What am I doing wrong?

$("#tree").dynatree({
        imagePath: 'skin-vista/',
        clickFolderMode: 2,
        autoCollapse: true,
        selectMode: 1,
        type: "GET",
        initAjax: {
            url: apiUrl + "Catalog/GetAllSectionNodes"            
        },       
        
        onActivate: function (node) {
            
            if (IsParentNode(node.data.key))
                return;        

        },
onPostInit: function() {
   console.log("postInit");
},
        postProcess: function () {
            console.log("postProcess");
        }
    });

mar10

unread,
Aug 7, 2013, 1:29:50 PM8/7/13
to dyna...@googlegroups.com, psaf...@googlemail.com
What DT version are you using?
Are you sure that the Ajax request is called (URL is correct)?
Any messages on the console?

You could try to debug it by setting a breakpoint somewhere arounf line 1830:


    if( options.postProcess ){

        data = options.postProcess.call(this, data, this.dataType);

    }



(One alternative could be to implement Ajax yourself as described '5.5.1 Loading custom formats')

Victor Lopez

unread,
Aug 7, 2013, 1:43:33 PM8/7/13
to dyna...@googlegroups.com, psaf...@googlemail.com
Thanks for the quick response.

I am using Version: 1.2.4

My ajax request is being processed correctly.  The tree loads fine without any issues or errors.

When writing to the console log, only the onPostInit and Create callbacks fire off.  However, the tree has not fully loaded/rendered at these points so I can't get a reference to it.

My requirement is simple:
  1. Have the tree load through an ajax call, which is working perfectly.
  2. After the tree is fully loaded, check a variable on the client for a valid key
  3. If the key is valid, select and expand the tree
Any guidance you can provide would be deeply appreciated.

v

mar10

unread,
Aug 7, 2013, 3:22:55 PM8/7/13
to dyna...@googlegroups.com, psaf...@googlemail.com
mot sure if I understood the requirement, but could you store the original request in a variable in `postProcess`, and then access it in  `onPostInit`?

Victor Lopez

unread,
Aug 8, 2013, 1:07:29 PM8/8/13
to dyna...@googlegroups.com, psaf...@googlemail.com
Thanks, I got it working using the 'onPostInit'

onPostInit: function (isReloading, isError) {
            var dbNode = this.getNodeByKey(clientKey);
            if (dbNode != null) {
                dbNode.activate();
Reply all
Reply to author
Forward
0 new messages