Problem with AjaxMethod and prototype

  1. #1

    Problem with AjaxMethod and prototype

    Hi,

    Just wanted to know if there was a workaround for the following problem. I have created a javascript class using prototype. This class handles the clicking of a treepanel to create new tabs into a tab panel. The reason for the prototype class is just to tidy everything up as my tabpanel and treeview are in different usercontrols.

    Anyhow the problem I have is that the prototype class is calling ajaxmethods from within it and I am using the { success : callback } feature. This does work but I think it is losing the scope as it makes the ajax call and returns. The callback fires but the prototype class has lots its settings eg. local values etc.

    I can see what the problem is here. The ajax method is fired and on return it has lost a reference to the TreePanelManager class. Just wondering if someone could figure out how I could regain the scope back. I have figured out a workaround of doing away with all local references using (this.tree) but rather use the instance (tpm._tree) but this kind of breaks OO.

    Below is some sample code of what I am doing .....

    
    vart tpm = new TreePanelManager('tree', 'tabPanel');
    
    TreePanelManager = function(tree, tabPanel){
        this._tree = tree;
        this._tabPanel = tabPanel;
        this._cbEditWindow = null;
        this._cbEditWindowOwner = null;
        this._tempAsyncNode = null;
    }
    TreePanelManager.prototype = {
    
        doSometing : function (owner){
        
                this._cbEditWindowOwner = owner;
                
                this._cbEditWindow = new Ext.Window({
                    title: 'Edit content',
                    layout: 'fit',
                    modal: 'true',
                    width: 800,
                    height: 600,
                    autoLoad: { showMask: true, mode: 'iframe', url: url }
                }); 
                this._cbEditwindow.show();
    
               Coolite.AjaxMethods.CreateNode({success: this.doResult});
                
        },
    
        doResult : function (result) {
    
               // do something with result
               // this._cbEditWindow always is null at this point
        }
  2. #2

    RE: Problem with AjaxMethod and prototype

    You can pass the scope to the success function. I dont think this is in the Coolite example page of documentation but it is in the ExtJS API doc for Ajax.Request

    http://www.extjs.com/deploy/dev/docs/?class=Ext.Ajax

    Coolite.AjaxMethods.CreateNode({
         success: this.doResult,
         scope: this
    });
  3. #3

    RE: Problem with AjaxMethod and prototype

    Hi,

    Thanks for the suggestion. Unfortunately it didnt work, it seems like it should so Im not sure if my implementation is wrong I will keep investigating....
  4. #4

    RE: Problem with AjaxMethod and prototype

    Hi,

    Try the following
    Coolite.AjaxMethods.CreateNode({success: this.doResult.createDelegate(this)});
  5. #5

    RE: Problem with AjaxMethod and prototype

    Again thank you....

    please mark as solved

Similar Threads

  1. [CLOSED] Ext.DatePicker.prototype.initComponent.createSeque nce
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 20, 2012, 2:20 PM
  2. prototype scriptaculous
    By Ian in forum 1.x Help
    Replies: 2
    Last Post: Apr 24, 2009, 7:00 AM
  3. A problem AjaxMethod and AjaxEvent
    By heysol in forum 1.x Help
    Replies: 2
    Last Post: Mar 23, 2009, 12:54 PM
  4. [CLOSED] AjaxMethod problem
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 30, 2009, 7:06 AM
  5. [CLOSED] Problem with ajaxmethod on masterpage
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 12, 2009, 12:39 PM

Posting Permissions