【问题标题】:Update Sqlite database from checkboxes从复选框更新 Sqlite 数据库
【发布时间】:2012-07-05 01:52:30
【问题描述】:

我有一组复选框,我想将它们的“选中”状态添加到数据库中。 我曾经像这样将它们添加到 localStorage:

    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)');

是否有一些方法可以从函数本身对数据库进行处理?

【问题讨论】:

    标签: jquery sqlite jquery-mobile cordova


    【解决方案1】:

    你应该使用:

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

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

    【讨论】:

      猜你喜欢
      • 2016-05-16
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 2016-04-29
      • 2011-11-04
      • 1970-01-01
      相关资源
      最近更新 更多