javascript - How can I get my variable to store the contents of another variable contained in a asynchronous function? -
i've been having issue week appreciate if can me. i'm working angular js , code gets remote json stores variable called jsonvar concatenate stored in sqlite db using html5sql library. have self invoking function runs code query db , stores results returned in variable called finalvar. issue is, need $scope variable store finalvar containing json saved database. appreciate help. here's code:
var showapp = angular.module('showapp', ['hmtouchevents']); showapp.controller('indexctrl', function ($scope, $http) { $scope.open = function (id) { webview = new steroids.views.webview("/views/show/show.html?id=" + id); steroids.layers.push(webview); }; function getstuff2(num) { $http.jsonp('http://whateverorigin.org/get?url=' + encodeuricomponent('http://www.catholic.com/api-radio/' + num) + '&callback=json_callback') .success(function (response) { result = angular.fromjson(response.contents); //this must called open connection database before statements processed html5sql.opendatabase("exampledb", "example database", 3 * 1024 * 1024); $(function () { var successfullstatements = $("#successfullstatements"), errors = $("#errors"); jsonvar = result.shows; //alert(jsonvar); html5sql.process( [ "drop table if exists starwarscharacters;", "create table if not exists starwarscharacters (id integer primary key autoincrement, name text);", "insert starwarscharacters (name) values ('" + jsonvar + "');", "insert starwarscharacters (name) values ('darth vader');", "insert starwarscharacters (name) values ('luke skywalker');", "insert starwarscharacters (name) values ('princess leia');", ], function () { //alert('great!'); }, function (error, statement) { errors.append("<li>" + error.message + " occured while processing: " + statement + "</li>"); } ); }); $(function () { var successfullstatements = $("#successfullstatements"), errors = $("#errors") html5sql.process( [{ sql: "select * starwarscharacters name=?;", data: [jsonvar] }], function (transaction, results, rowsarray) { (var = 0; < rowsarray.length; i++) { finalvar = rowsarray[i].name; } }, function (error, statement) { } ); }); $scope.shows = finalvar; //getlist(); }); steroids.view.navigationbar.show("shows"); id: "show_id" }; function getstuff1() { $.getjson('http://whateverorigin.org/get?url=' + encodeuricomponent('http://www.catholic.com/api-radio/latest') + '&callback=?', function (data) { var obj = data.contents; obj = json.parse(obj); var latestnum = obj.latest; //alert('works'); var numbers = new array(50); (i = 0; < 50; i++) { x = latestnum - i; numbers[i] = x; //alert(numbers); } getstuff2(numbers); return data.contents; }); } getstuff1(); }); // show: http://localhost/views/show/show.html?id=<id> showapp.controller('showctrl', function ($scope, $filter, $http) { // fetch objects local json (see app/models/show.js) (function (shows) { // select 1 based on view's id query parameter $scope.show = $filter('filter')(shows, { show_id: steroids.view.params['id'] })[0]; }); // -- native navigation steroids.view.navigationbar.show("show: " + steroids.view.params.id); });
Comments
Post a Comment