I'm using Cordova (Drupalgap) to make a mobile app for my website. I'm a Javascript novice, and I have a function that creates a page (mymodule_home_auth_page()). Inside that function, I want to call another function, mymodule_get_unread_pm_count() (to check whether the user has unread messages), and, if this function returns a value, I want to add some markup to content[] inside the parent function.
However, the content[]
markup in the function-inside-the-function is not printed to the display. The function mymodule_get_unread_pm_count() does return a value because when I load the app the alert()
is called, informing me I have unread messages, but the markup is not printed to the display.
I assume this has something to do with scope, but I don't understand what I need to change to allow me to inject something into content[]
in the parent function.
Here is the code I am using now:
function mymodule_home_auth_page() {
try {
var content = {};
content['header'] = {
markup: '<h1>Hello world</h1>',
}
};
mymodule_get_unread_pm_count({
success: function(result) {
content['unreadmessages'] = { markup: '<h2>You have unread messages</h2>'};
var num_unread = result[0];
alert('You have' + num_unread + 'unread messages.');
return content;
}
});
content['footer'] = {
markup: '<p>Nothing to see down here.</p>',
}
};
catch (error) { console.log('mymodule_home_auth_page - ' + error); }
}