views:

49

answers:

2

My callback code (js file) is something like

function addcontent(Title, tUrl, bURL, Id,purl){

  alert(Id)

  var runcontent = new Ext.Panel({
    id: 'tt' + Id,
    region: 'center',
    autoLoad: {
      url: tUrl, 
      callback: function(el){
        addwindow(el, Id, bURL,purl);
      }, 
      scripts: true, 
      nocache: true
    },
    width: 600,
    collapsible: false
  });
}

function addwindow(el, Id, bURL,purl) {

  //alert(el);
  alert("add buttons   " +{Id);
}

My problem is the call function is not going to addwindow. When I alert “Id” in addcontent it is displaying but not addwindow as the control is not moving to addwindow. How can I trace/track what is the exception which is preventing the control to move onto addwindow.?

+1  A: 
function addcontent(Title, tUrl, bURL, Id,purl){

  alert(Id)

  var runcontent = new Ext.Panel({
    id: 'tt' + Id,
    region: 'center',
    autoLoad: {
      url: tUrl, 
      callback: addwindow(Id, bURL,purl),
      scripts: true, 
      nocache: true
    },
    width: 600,
    collapsible: false
  });
}

function addwindow(Id, bURL,purl) {

  //alert(el);
  alert("add buttons   " +Id);
} 
Xupypr MV
callback function expects first argument to be an instance of `Ext.Element` not a string, second to be a boolean value, and third to be a XMLHttpRequest. So yeah: -1
Mchl
Yes. But you need specify special callback function only if you need some additional data. You can directly invoke any function in callback.
Xupypr MV
And the return of this unction will be passed to callback option... wait a moment... it does make some sense :D - reverting vote - ah too late, you'd need to edit your answer for me to be able to change my vote
Mchl
NVM: Forgot I can edit too :P
Mchl
This is not correct. It only happens to look like it works because the scope is global and the Id does not change between call and callback. However, the "callback" function is executing _immediately_ in this code as defined, not after the callback. You would have to use createCallback() or createDelegate() to define the callback with params like this.
bmoeskau
+1  A: 

The proper approach to creating the callback with params is to use createCallback or createDelegate. Your functions are (apparently) executing in global scope so it wouldn't make much practical difference, but createDelegate allows your callback to execute within the same scope as the original function, which makes it the best default choice usually. So it would be something like:

autoLoad: {
  url: tUrl, 
  callback: addwindow.createDelegate(this, [Id, bURL,purl]),
  scripts: true, 
  nocache: true
},

Again, note that the this in your case will be the global Window object, but this is still a good practice to get into so that doing the same thing in the future within a class method will work as expected.

bmoeskau