I am struggling with javascript and learning callbacks, and applying this to SharePoint 2010 specific js/jquery methods of getting and savings values from lists. So I am recently getting into the following method (i know there are others but I would like to learn this one):
function getListData()
{
var gridURL = "http://spdev:42977/sites/devcenter/_vti_bin/ListData.svc/Projects";
var request = new Sys.Net.WebRequest();
request.set_httpVerb("GET");
request.set_url(gridURL);
request.get_headers()["Accept"] = "application/json";
request.add_completed(onCompletedCallback);
request.invoke();
}
function onCompletedCallback(response, eventArgs) {
var getProject = eval("(" + response.get_responseData() + ")");
var buildMarkUp = "";
for (var i = 0; i < getProject.d.results.length; i++) {
buildMarkUp += "<div>" + getProject.d.results[i].Title + " </div>";
var passID = getProject.d.results[i].ProjectID;
// need a nested call to go out and get items from related lists using the passID varible, and build table/grid
}
so i trying to build a data grid, and for parent item, or project ID/Title that comes back on the list has several related data values stored in other lists that I need to pull, but I can't seem to figure out how to apply callbacks to the above method (over and over for each list I need to pull from since they have their own very specific pre-defined callbacks returning the data already).
So I asked a similiar question on stack which got me pointed in the direction of callbacks in the first place (new to me). I am beginning to understand this in a basic sense....
hence the example here.
I tried playing around with the SP method like:
request.add_completed(onCompletedCallback, passedAdditionalValue);
thinking I might be able to keep passing and build the string through all the repeat functions and callbacks. adding additional parameter to the successfulCallback doesn't work because it breaks the response, eventArgs......response not define.
how would i go about using the getListData() listdata.svc with callback method per above, then use it again (2 or 3 times more) to get additional relative data, using more callbacks? or something like this to achieve the desired result. I can't seem to figure out how to apply the general callbacks to the SP specific example.
greatly appreciated as always!