如何使用 JsStore 填充索引数据库中的 DateTime 列

问题描述 投票:0回答:1

这是我的桌子:

{
        name : "TEST",
        columns : {
            K_A : {dataType : "string"},
            DT_VAL : {dataType : "date_time"},
            DT_SENT : {dataType : "date_time"},
            pk: {
                primaryKey: true,
                keyPath: ['K_A', 'DT_TRACE']
            },
            sent: {
                keyPath : ["DT_SENT"]
            }
            
        }
    }

我完全无法在此表中插入记录。我不知道日期时间列的格式。我尝试了几乎所有的解决方案:new Date(); Date.now()、new Date().toISOString()、new Date().toGMTString()、new Date().toUTCString()、new Date().toString()...没有任何效果。

dt=new Date().toISOString();
record={ K_A:"A", 
         DT_VAL: dt,
        DT_SENT: dt 
        };

// 使用jsStore db.connection.insert({ 进入:“测试”, 更新插入:true 值:记录, 验证:假});

无论我尝试什么,我都会得到这个:

 Uncaught (in promise) 
Object { message: "Data provided to an operation does not meet requirements.", type: "DataError" }
javascript datetime indexeddb
1个回答
0
投票

问题似乎出在keypath的使用上。

(请注意,在我的帖子中,键路径是['K_A','DT_TRACE'],但在我的代码中它是正确的:['K_A','DT_VAL'],只是发布时的复制/剪切错误)

无论如何,删除键路径并使用 new Date() 是可行的。

{
    name : "TEST",
    columns : {
        K_A : {primaryKey: true, dataType : "string"},
        DT_VAL : {primaryKey: true, dataType : "date_time"},
        DT_SENT : {dataType : "date_time"},
    }
}

record={ K_A:"A", 
         DT_VAL: new Date(),
        DT_SENT: new Date() 
        };
© www.soinside.com 2019 - 2024. All rights reserved.