2012-07-04 115 views
2

我有一组复选框,我希望将其“已检查”状态添加到数据库。 我曾经将它们添加到像这样的的localStorage:从复选框更新Sqlite数据库

function SaveData() 
    { 
     var status = $('input[type="checkbox"]').filter('.custom').map(function(){ 
     var name = $(this).attr('name'); 
     var CheckBoxId= $(this).attr('CheckboxId');            
     if($(this).is(':checked')) 
     return { 'name':name, 'status' : 'Checked', 'CheckBoxId':CheckBoxId}; 
     else 
     return null; 
     }); 
     localStorage["Days"] = status.length; 

     for(var i = 0;i<status.length;i++) 
     { 

      localStorage["Day" + i] = status[i].name; 


     } 
    } 

现在我想将它们添加到SQLite数据库,但是当我添加任何陈述喜欢这里,JavaScript的网页是没有看到在所有的,所以我不我不知道我应该在哪里写这份声明。

 for(var i = 0;i<status.length;i++) 
     { 
      tx.executeSql('UPDATE WeekDay SET Checked = 1 Where WeekId= status[i].CheckBoxId'); 

     } 

这是在数据库中的表:

tx.executeSql('DROP TABLE IF EXISTS WeekDay'); 
    tx.executeSql('CREATE TABLE IF NOT EXISTS WeekDay (id unique, DayName, Checked INTEGER)'); 

是有一些方法来从函数本身内的数据库上运行?

回答

1

您应该使用:

tx.executeSql('UPDATE WeekDay SET Checked = 1 Where WeekId= ?', [status[i].CheckBoxId]); 

你不能直接从查询引用变量,你必须插入它的价值。