简体   繁体   中英

Process the result of an executeSql statement using Handlebars.js

This is a simplified scenario:

var dbo = openDatabase('xxx','1.0','xxx', 1048576);
myPromise = new $.Deferred();
dbo.transaction(function(myTrans) {
    myTrans.executeSql(
        'SELECT * FROM myTable',
        [], 
        function(tx, result) {
            myPromise.resolve(result);
        }
    );
});
myPromise.done(function(result) {
    var X = $('#result-template').html();
    var template = Handlebars.compile(X);
    template(result.rows);
});

I think everything is working up to the 2nd to the last line - the template(result.rows) line.

Edit: Here is a jsFiddle with everything from dropping the table, creating it, populating it, selecting from it and (trying to) display the result.

The last line should be something like:

$('ul').append(template(data));

VOTE FOR PEDRO!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM