View Full Version : Getting a proper return value

14 Mar 2011, 9:51 AM
I need some help in regards to returning a value.

The scenerio is setup like this. Theres is a function that is called that needs to return a string. But in order to compile that string the function has to initiate 1 or more Ext.store.load() calls to get data that is processed through the load's configured callback.

The problem I have is that of the nature of Async design and that processing is finished and returned to the calling function before the callbacks have had a chance to process.

I am at a loss of the best way to handle this so that all the processing from the load callbacks is finished before I return the value.

// Grid Selection Model is configured for Checkbox
var selectedRecords = grid.getSelectionModel().getSelections(),
files = '';
Ext.each(selectedRecords, function (record) {
var project = record.get('ProjectID');
myStore.setBaseParam('RootFolder', project);
scope: this,
callback: function (records, options, success) {
Ext.each(records, function (record) {
var url = record.get('Url');
if (Ext.isEmpty(files)) {
files += url;
} else {
files += ',' + url;
}, this);
}, this);
return files;

14 Mar 2011, 1:54 PM
Maybe you could have a look at createDelegate(). It's in the docs under Function.

14 Mar 2011, 2:40 PM
Seems like it should be a lot simpler if you just pass all the project id's to the server in one request. Server can figure it out and return what needs to be returned...?

14 Mar 2011, 2:45 PM
exactly what i would do. And use an empty array where you simply push the id's to

var ids = [];
return ids;
//or if you really need a comma list
return ids.join(',');

15 Mar 2011, 4:24 AM
Unfortunately I cannot combine the calls because the backend is sharepoint list. It can only deal with one filter using the method I "have" to work with

However it still doesn't seem to accomplish keeping the function from getting a return value before the store callback is done.