87,996
社区成员




<script>
var arr = ['a', 'b', 'c', 'd', 'e'];
var db = openDatabase('test', '1.0.0', '', 65535);
db.transaction(function (t) {
t.executeSql('create table if not exists test(id INTEGER PRIMARY KEY AUTOINCREMENT,name text,pid int)', null,
function () {
t.executeSql('delete from test', null, function () {
console.log('delete ok')
t.executeSql("insert into test(name,pid)values('" + arr[0] + "',0)", null, function () {
console.log('insert ok')
Insert(1);
}, function () { console.log(arguments) })
}, null)
}, null);
});
function Insert(i) {
db.transaction(function (t) {
t.executeSql("select id from test where name='" + arr[i - 1] + "'", null, function (t, rs) {
var id = rs.rows.item(0).id;
console.log(id)
t.executeSql("insert into test(name,pid)values('" + arr[i] + "'," + id + ")", null, function () {
if (i + 1 < arr.length) Insert(i + 1);
else {//arr全部插入,查看数据库记录
t.executeSql('select * from test', null, function (t, rs) {
alert(JSON.stringify(rs.rows))
})
}
}, null);
}, function () { console.log('查询id失败') })
})
}
</script>