1

我正在使用 phonegap、jquery mobile、sqlite 数据库制作 android 应用程序

我在其中在线同步数据,但我需要您的帮助如何离线同步

在 HTML5 中:-

<div id="emp" data-role="page" class="body">
    <div date-role="content" id="content">  
        <div class="select">
           <ul id="employee1"></ul>
        </div>
    </div>       
</div>

在 JQuery 中:-

   var db;                                            
   var short_Name='Employee__DB';
   var version='1.0';
   var display_Name='Employee__DB';
   var max_Size='65535';

   $(document).bind("pageinit", function () {
         $(location).attr('href', '#emp');
         on_Employee_DB_Create();
     employeeee();
   });

   function on_Employee_DB_Create(){
         db = window.openDatabase(short_Name ,version ,display_Name ,max_Size);                      

         db.transaction(function(transaction){
      transaction.executeSql( 'DROP TABLE IF EXISTS E_Emp',nullHandler,nullHandler);

       transaction.executeSql( 'CREATE TABLE IF NOT EXISTS E_Emp(_idEE INTEGER PRIMARY KEY, Emp_ID TEXT,Emp_Name TEXT)', []);
       },errorHandler,successCallBack);
    }

    function employeeee(){
         $("#employee1").empty();
     $.support.cors = true; 
     $.ajax({
               type: "GET",
               url: "one.xml",
               contentType: "text/xml",
               dataType: "xml",
               data: "",
               crossDomain:true,
               success: function (data) {       
                       $(data).find("employee").each(function ()       {                          
                var emp_id = $(this).find('id').text();
                 var emp_name = $(this).find('short_name').text();
                var scripts = "<li><a href='#'>"+emp_name+"</a></li>";  
                        $("#employee1").append(scripts).trigger("create");
                    db.transaction(function(transaction) {
                     transaction.executeSql('INSERT INTO E_Emp VALUES((SELECT max(_idEE)+1 FROM E_Emp),"'+emp_id+'","'+emp_name+'")',nullHandler,errorHandler);
                 });
            });
       }
   });  
 }
4

0 回答 0