javascript - Passing an array to a function and pushing values to it using AngularJS -


i trying populate arrays dynamically local storage sqlite database tables when controller loaded.

i have several arrays defined follows (small sample shown):

$scope.myarray1 = []; $scope.myarray2 = []; 

i create array table name/array name associateion e.g. my_table_1 should queried , written $scope.myarray1. looks below (small sample shown):

$scope.tablearrayassociation = [{     tablename: "my_table_1",     arrayname: "myarray1" }, {     tablename: "my_table_1",     arrayname: "myarray2" }]; 

to have function calls sqlite local storage database table , reads values it.for function pass table name query , array write data function parameters.

i can query required table no problem passed parameter, when try , insert array error. below said function.

ondeviceready

function ondeviceready() {     querylocalstoragetablesandbuildarrays($scope.tablearrayassociation); } 

loop through each item, query table , push array.

function querylocalstoragetablesandbuildarrays(tablearrayassociation) {      (var = 0; < $scope.tablearrayassociation.length; i++) {         querytable($scope.tablearrayassociation[i].tablename, $scope.tablearrayassociation[i].arrayname); }  function querytable(tablename, arrayname) {     var sql = 'select * ' + tablename + ''; // ok     db.transaction(function (tx) {         tx.executesql(sql, [],             (function (arrayname) {                 return function (tx, results) {                     querysuccess(tx, results, arrayname);                 };         })(arrayname), errorcb); // ok     }); }  function querysuccess(tx, results, arrayname) {     var len = results.rows.length; // ok      (var = 0; < len; i++) {         $scope[arrayname].push(results.rows.item(i)); // not working here         arrayname.push(results.rows.item(i)); // tried this, arrayname.push not function error thrown     } } 

arrayname.push(...) not working because trying push name (string) , not actual array. showing log $scope[arrayname] shows object push didnt work - value = undefined.

can please suggest solution this? how assign queried tables values corresponding array populate values in view?


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -