用变量生成数据库web sql database 及操作需要JSON.stringfy/parse来操作

用变量生成数据库web sql database 及操作需要JSON.stringfy/parse来操作:

var newstr = 'checkbox0,input1,textarea2,option3,date4,flag'
var newdatastr = '0,1,2,3,4,5'

const a = 'CREATE TABLE IF NOT EXISTS ' + taname +  ' (id integer primary key AutoIncrement,'+newstr+')'
            const b = JSON.stringify(a);


            const c = 'INSERT INTO ' + taname + ' (' +newstr+ ') VALUES (' +newdatastr+ ')'
            const d = JSON.stringify(c);

            db.transaction(function (tx) {
                tx.executeSql(
                    JSON.parse(b)

                )
            })

            db.transaction(function (tx) {
                tx.executeSql(
                    JSON.parse(d)

                )

            })
posted @ 2023-02-09 19:03  grantgrant  阅读(27)  评论(0)    收藏  举报