Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
var query=" SELECT * FROM measurements WHERE project_type=? AND project_id= ? AND subproject=? LIMIT 1";



$cordovaSQLite.execute(db, query, ['SMBH',$scope.proj1,'DRILLING AND COMPLETION OF 5 INCH DIAMETER BOREHOLE BASEMENT']).then(function(result) {

$scope.results=[]; 

if(result.rows.length >0){

for(var i=0; i<result.rows.length; i++){
   //alert("items exists");
sub["add"] = result.rows.item(i).address;
sub["award"] = result.rows.item(i).date_awarded;
sub["rep"] = result.rows.item(i).reporter_id;
sub["contr"]= result.rows.item(i).contractor_id;
for(var m=1; m<=49;m++){
var l="l";
sub["l"+m] = result.rows.item(i).l1;//FETCHES THE RESULT
sub["l"+m] = result.rows.item(i)+l+m;//DOESN'T FETCH THE RESULT

sub["b"+m] = result.rows.item(i).b1;//FETCHES THE RESULT
sub["d"+m] = result.rows.item(i).d+m;//DOESN't FETCH THE RESULT
sub["num"+m] = result.rows.item(i).num1;//FETCHES THE RESULT
sub["cr"+m] = result.rows.item(i).certified_rate1;//FETCHES THE RESULT


What I have tried:

sub["d"+m] = result.rows.item(i).d+m;
sub["d"+m] = result.rows.item(i)."d"+m;
sub["d"+m] = result.rows.item(i).d+[m];
sub["d"+m] = result.rows.item(i)+"."+d+[m];
Posted
Updated 6-Aug-17 1:28am

1 solution

JavaScript
sub["l"+m] = result.rows.item(i).l1;//FETCHES THE RESULT
sub["l"+m] = result.rows.item(i)+l+m;//DOESN'T FETCH THE RESULT

This first line gets the member called 'l1' of the item, while the second gets the item object and try to add to it 'l' and '1', that's really not the same...
You may use here the fact that members in JavaScript can be accessed in two ways...
The . (dot) operator - as you do it in the first line
and [] - as you use with arrays (it works because JavaScript represents object like a hash table, where member name is the key)
So you may write the second line like this:
JavaScript
sub[l + m] = result.rows.item(i)[l + m];
 
Share this answer
 
Comments
Member 13348179 6-Aug-17 11:13am    
Thanks a lot kornfield i got it working this way sub["l"+m] = result.rows.item(i)['l'+m];

Correction taken.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900