Hey all I've just been fooling around with the HTML5 Database API and I'm having trouble return the result from a function. Here is what I have.
var list = GetScenarios();
GetScenarios: function()
{
var scenarios;
// get all the scenarios
conn.transaction(function(_t) {
_t.executeSql('SELECT * FROM scenarios', [], function(_tr, _result) {
scenarios = _result.rows;
});
});
return scenarios;
}
I manage to get the rows from the db but the rows wont assign to the variable scenarios. I know its a scope thing but I can't think how to return the result from the GetScenatios function.
When I log _result.rows I have the data there but scenario is always undefined;
Any thoughts?
Here is how my js file is setup.
window.MyExtension = (function()
{
return ({
OtherMethod: function() {
var list = window.MyExtension.GetScenarios();
},
GetScenarios: function() {
...see above
}
}());
GetScenarios: function()should befunction GetScenarios(). It could beGetScenarios = function()but then it would have to appear beforevar list = GetScenarios();.function GetScenarios()works, as proven by your jsFiddle. But,GetScenarios = function()does not, as evidenced by this one: jsfiddle.net/FvdbT/1