I want to return a value from nested functions in my cordova/javascript application with some plugins, but it doesn't work as supposed:
if(restaurantsNearby == true) {
if(restaurantNameArr.length == 1){
return restaurantNameArr[0].rID;
} else {
return actionSheet(restaurantNameArr);
}
}
var actionSheetCallback = function(buttonIndex) {
return window.restaurantNameArr[buttonIndex-1].rID;
};
function actionSheet(restaurantNameArr) {
var restaurantNames = new Array();
$.each(restaurantNameArr, function(key, value) {
restaurantNames.push(value['rName']);
});
var options = {
'title': 'Where are you?',
'buttonLabels': restaurantNames,
'androidEnableCancelButton': false,
'winphoneEnableCancelButton': false
};
window.restaurantNameArr = restaurantNameArr;
window.plugins.actionsheet.show(options, actionSheetCallback);
return actionSheetCallback;
};
I want to return the value of window.restaurantNameArr[buttonIndex-1].rID
with the first if
-statement, but it doesn't work.
EDIT restaurantNameArr
looks like [{rID: '188', rName: 'Taverne'}, {rID: '192', rName: 'Pub'}, {rID: '193', rName: 'Ducis'}, ...]