PDA

View Full Version : grid datastore.reload scope, posible bug?



TopKatz
23 Apr 2007, 9:20 AM
First let me state Im ra relative newb with OO JS.

I have been working on a messaging system. It is using a layout dialog with a grid. When you click a row (message) in the grid, it opens a second dialog that displays the message details. I was working on getting the grid to update after I delete the message in the detail dialog view and close the second dialog.

I experimented with a couple of different ways to get the datastore object over to teh second dialog so I could perform the reload. Im sure I used some bad technique's to do this. First I put the datastore var outside of the gridDialogs method. Making it a global. This worked, however it had some weird results. When I triggered this reload, every instance of the httpproxys request would all go off again. So if I had made say 10 different requests, they would all try and reload simultaneously. So next I brought the ds var back into my gridDialog method, and handed the datastore object off with a function that I was using to pass vars off to the second dialog. I then assigned it a private var in the second dialogs method, and again I could use the datastore object to reload, but it again had the same strange result of reloading all of the http requests that had been made.

In the end I added another function to my gridDialog method to perform a datastore.reload(), I then just called gridDialog.reload(), and everything seams to be playing nice.

Im going to assume that the behavior I was seeing was not a bug, but bad programing on my part. I think it had to do with scope, but Im to green to know for sure. Anyways, I figured I would post this so that if it is a bug you guys could check it out.

Katz

tryanDLS
23 Apr 2007, 9:41 AM
Without seeing code, it's hard to say. Post a small example that duplicates the problem and we'll take a look at it.

TopKatz
23 Apr 2007, 9:55 AM
Here is an example of the approaches I took, keep in mind these are not working examples, just mock ups to show how I passed the object.

Example 1:




var gridDialog = function(){
var ds;
return {
init : function(){stuff},
showDialog : function(){

ds = new Ext.data.HttpProxy({stuff})

function rowClicked(grid, rowClicked, e){

viewMessage.showDialog(ds) // pass the ds off to the second dialog!
}
}
}

var viewMessage = function(){
var ds;

return {
init : function(){stuff},
showDialog : function(ds){ //reciving the ds object from the gridDialog!

ds = ds; //asighn the ds object to a local var!

}

deleteMsg : function(){

msgDialog.hide();
ds.reload(); // reload the grid from the first dialog when I close the second
},
}
}

}



This example works, however it will reload every instance of my http proxy again. It will behave the same way if I declare ds global (out side of the gridDialog) then call the datastore from inside the viewMessage method.

Again, I have it working properly now, however I thought I should let someone look at this who knows more then I. I hope this helps explain what I did.