HTML5 webSQL dynamically queries the front-end database table, html5websql
// HTML5 web SQL queries data $ scope. queryCenterReimbursData = function (keyword, querycol) {var lencr = "0"; // concatenate sqlvar condition = ""; // filter condition var conditiontemp = ""; // temporary filter condition variable var querycrsql = ""; // finally execute SQLvar queryzxcols = new Array (); // queryzxcols = ["1 ", "2"] var selcolsql = ""; // query the field for (var I = 0; I <colattrs. length; I ++) {selcolsql = selcolsql + "" + colattrs [I] + "," ;}selcolsql = selcolsql. substring (0, (selcolsql. length-1); // query a field Zxcols = querycol. split (","); for (var I = 0; I <queryzxcols. length; I ++) {if (I = 0) {conditiontemp = colattrs [queryzxcols [I] + "LIKE" + '\ "' + keyword + '% \"';} else {conditiontemp = "OR" + colattrs [queryzxcols [I] + "LIKE" + '\ "' + keyword + '% \"';} condition = condition + conditiontemp;} // limit the number of limit queries. Google's webSQL uses the sqlite database querycrsql = "SELECT" + selcolsql + "FROM (SELECT * FROM" + tableuniqueflag + "WHERE" + condition + ") limit" + rowsize; if ("" = keyword) {querycrsql = "SELECT" + selcolsql + "FROM" + tableuniqueflag + "limit" + rowsize;}/console. log ("querycrsql =" + querycrsql); // concatenate SQL // var db = openDatabase ('mydb14', '1. 0 ', 'test db', 6*1024*1024); var DB = DataSourceService. getConnection (); db. transac Tion (function (tx) effectx.exe cuteSql (querycrsql, [], function (tx, results) {lencr = results. rows. length; // number of entries returned by len temprow control results var datacr = ""; // query the second-level code var datasum = ""; for (var I = 0; I <lencr; I ++) {datacr = '{'; for (var j = 0; j <showcols. length; j ++) {var colattrsj = showcols [j]. map; if (j = (showcols. length)-1) {// json {"name": "zhangsan ",......} Datacr = datacr + '\ "' + colattrsj + '\"' + ":" + '\ "' + results. rows. item (I) [''+ colattrsj +''] + '\ "';} else {datacr = datacr + '\"' + colattrsj + '\ "' + ": "+ '\"' + results. rows. item (I) [''+ colattrsj +''] + '\ ",' ;}} if (I = (lencr-1) {// concatenates into a json object array. [{Json object}, {json object}, {json object}] // The Last json object must have no comma; otherwise, JSON. parse (datasum); conversion fails. Datacr = datacr + "}";} else {datacr = datacr + "}," ;}datasum = datasum + datacr;} datasum = '[' + datasum + ']'; console. log (datasum) tableresultjson = JSON. parse (datasum); if (lencr> 0) {if (lencr <rows) {rows = lencr + 1;} $ scope. createMyTable (rows, cells); // assign the title for (var j = 1; j <parseInt (cells) + 1; j ++) {var titlecol = titlecols [J-1]; var titleid = "#" + tableuniqueflag + "1" + "" +j1_1_(titleid1_.html (titlecol);} // assign table content var nn = 0; for (var I = 2; I <parseInt (rows) + 1; I ++) {for (var j = 1; j <parseInt (cells) + 1; j ++) {var colattr = colattrs [J-1]; var tdid = "#" + tableuniqueflag + I + "" +j1_((tdid1_.html (tableresultjson [nn] [''+ colattr +'']);} nn = nn + 1;} // select the first row of the default table (except the header row) $ ("#" + tableuniqueflag + "2 "). addClass ("checktrcolor" );((mydivlocation).css ('display', 'block'); rows = rowsize;} // else {// ((mydivlocation..css ('display', 'None '); // }}, null );});}
Spliced json object Array
[
{
"AKB020": "00001 ",
"AKB021": "service station 1 ",
"AKA020": "ftqcxdjdyhzsqwsfwz"
},
{
"AKB020": "00002 ",
"AKB021": "service station 2 ",
"AKA020": "ftqdhmjdshsasqwsfwz"
},
{
"AKB020": "00003 ",
"AKB021": "service station 3 ",
"AKA020": "ftqlgqjdlblsqwsfwz"
}
]
Application:
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.