tags:

views:

67

answers:

2

I cant seem to find a way to make django-dajaxice have its callback inside same scoped object from which made the initial call.

 MyViewport = Ext.extend(MyViewportUi, {
    initComponent: function() {
        MyViewport.superclass.initComponent.call(this);
    },

    LoadRecordsCallback: function(data){
       if(data!='DAJAXICE_EXCEPTION')
      { alert(data); }
      else
      { alert('DAJAXICE_EXCEPTION'); }  
    },

    LoadRecords: function(){
      Dajaxice.Console.GetUserRecords(this.LoadRecordsCallback);
    }
 });

 var blah = new MyViewport();
 blah.LoadRecords();

I'm on django, and like the calling syntax to django-dajaxice. I'm using Extjs 3.2 and tried passing a Ext.createCallback but Dajax's returning eval seems to only want a string for the callback.

A: 

I'm not familiar with django at all, but I think I understand the problem.

It seems that the API mandates that you pass a string which will be eval'd as a function call, so you must pass the name of the function, rather than the function itself.

This in turn means that it must be a name that is meaningful at the window scope - either a function defined outside of an Ext class (e.g. "myGlobalFunction"), or a member function of an Ext class that is accessible as a variable (e.g. "window.blah.LoadRecordsCallback")

ob1
A: 

BozoJoe, this should work.

MyViewport = Ext.extend(MyViewportUi, {
    initComponent: function() {
        MyViewport.superclass.initComponent.call(this);
    },

    LoadRecordsCallback: function(data){
       if(data!='DAJAXICE_EXCEPTION')
      { alert(data); }
      else
      { alert('DAJAXICE_EXCEPTION'); }  
    },

    LoadRecords: function(){
      Dajaxice.Console.GetUserRecords('blah.LoadRecordsCallback');
    }
 });

 var blah = new MyViewport();
 blah.LoadRecords();
Benito Jorge Bastida