PDA

View Full Version : JS Question



booshan
18 Apr 2007, 1:25 PM
Gurus,

I have created an objects that extends Grid. It works fine, but if you look at the code, I am storing the references of dataSource and getView() in local variables in order to access it inside the function onSuccess. B'se I am not able to directly access dataSource and getView(). How can I avoid these using such local variables? Appreiciate your help!

Thanks
Booshan



Ext.extend( BasePanel, Ext.grid.Grid, {
reload : function( loadUrl, params) {
var myDataSource = this.dataSource;
var myView = this.getView();
new Ajax.Request( loadUrl, { method: 'get', parameters: params,
onSuccess: function( req) {
var records = eval( '(' +req.responseText +')');
myDataSource.removeAll();
myDataSource.loadData( records, true);
myView.refresh();
},
onFailure: function(req){
alert( req.responseText);
if(req.status == 401) {
window.location.href="index.html";
}else{
var msg = "Update Failed. " + req.responseText;
popup.show({title : "Info", type : popup.OK_CONTROLS, message : msg});
}
}
});
}
});

tryanDLS
18 Apr 2007, 1:43 PM
What is 'this' pointing to in your methods? I don't know what Ajax.Request is, but it would appear that it's not setting scope when it calls your success/failure methods. If you're not going to use the built-in Connection class, you should at least see how it deals with scoping.