• indexedDB基本使用demo


    <html>
    <head>
        <script src="jquery-3.5.1.js"></script>
    </head>
    <body>
    <script>
        createOrOpenDb("teamtalk");
        //新建或打开已有数据库
        function createOrOpenDb(dbName){
            var request = indexedDB.open(dbName, 1);
            request.onsuccess = function(event) {
                console.log('打开/创建 数据库成功');
            };
            request.onerror = function(event) {
                console.log('打开/创建 数据库成功失败:' + event.target.error.message);
            };
        }
    
        function insertData(db){
            /**
             * 第一个参数,存储空间的名称,即上面的customers。
             * 第二个参数,keyPath值指定主键。
             * autoIncrement指定了key值是否自增(当key值为默认的从1开始到2^53的整数时)。
             * */
            var objectStore = db.createObjectStore("customers" , { keyPath: "name" }  );
            /**
             * 第一个参数,索引的名称。
             * 第二个参数,指定索引对应列。
             * 第三个属性, options对象,其中属性unique的值为true表示索引必须唯一。
             * */
    //          objectStore.createIndex("name", "name", { unique: false });
            objectStore.add({"name": 'a', "age": "10",ssn: "444-44-4444"});
            objectStore.add({"name": 'b', "age": "20",ssn: "444-44-4442"});
        }
    
        function deleteData(db, storename, id){
            var transaction = db.transaction(storename, 'readwrite');//获取事务
            var store = transaction.objectStore(storename); // 得到对应的object store
            store.delete(id);// 根据id删除对应store中的数据
        }
    
        function readData(db, storename, id){
            var transaction = db.transaction(storename, 'readwrite');
            var objectStore = transaction.objectStore(storename);
            var req = objectStore.get(id);
            req.onsuccess = function(e) {
                var employee = e.target.result;//得到对象
                debugger
            };
        }
    
        function updateData(db, storename, id){
            var transaction = db.transaction(storename, 'readwrite'); //获取事务
            var store = transaction.objectStore(storename);// 得到指定的object store
            var req = store.get(id);//根据id查找指定的对象
            req.onsuccess = function(e) {
                var employee = e.target.result;//得到对象
                employee.age = 19;//修改值
                store.put(employee);//将修改之后的值放回指定的object store中
            };
        }
    </script>
    
    </body>
    </html>
  • 相关阅读:
    django报错信息解决办法
    postgresql数据库的基本使用
    Ubuntu 18.04中安装PostgreSQL(PSQL)
    Ubuntu 18.04 安装 PyCharm
    在Ubuntu中安装Docker和docker的使用
    ubuntu怎么切换到root用户,切换到root账号方法
    centos7彻底卸载mysql和通过yum安装mysql
    django运行时报错处理方法
    Django 查询时间段 时间搜索 过滤
    View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers
  • 原文地址:https://www.cnblogs.com/xiaoliu66007/p/14384076.html
Copyright © 2020-2023  润新知