How to implement an SQLite database in Phonegap?

前端 未结 4 1925
长发绾君心
长发绾君心 2020-12-29 11:22

I\'m implementing a cross-platform app for Android, iOS, and BlackBerry. I\'m using PhoneGap to produce native language versions for each platform. I want to know how to cre

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 11:45

    Take a look at Lawnchair (http://brian.io/lawnchair/), its pretty easy to use and out-of-the box probably does most of what you need (including searching), it's cross-browser, battle tested and degrades nicely through the use of adapters. There is an adapter for Blackberry, and a plugin that supports queries. Here is quick example using the webkit adapter, which is good for Android and iPhone, to show how simple it is.

     
    
    
    // Open local DB connection
    var lawnchair = new Lawnchair({table:'mytable', adaptor:'webkit'}, function(){
        // Lawnchair setup! 
    });
    
    // Getting some data out of the lawnchair database
    lawnchair.get('my_data_key', function(obj) {
        if (obj !== undefined) {
            lastSyncDate = obj.lastSync;
            dataList = obj.dataList;
        }
    });
    
    // Saving to the database
    lawnchair.save({key:'my_data_key', lastSync: currentTime, dataList: someData});
    

提交回复
热议问题