方法没有返回值 js

vbn19456 发布于 2021/08/26 14:21
阅读 71
收藏 0

NGINX社区官方微服务训练营,深入了解K8s网络,线上课程+专家答疑,立即加入>>>

下面这个方法get不知道为什么没有返回值
var   request  =  window . indexedDB . open ( "tools" );
var   mode  =  "readwrite" ;
var   db ;
 
request . onsuccess  =  function () {
     db  =  this . result ;
}
request . onerror  =  function ( e ) {
     console . log ( e );
}
request . onupgradeneeded  =  function ( e ) {
     db  =  e . target . result ;
     var   store  =  db . createObjectStore ( "title" , {
         keyPath:   "dataIndex"
    });
     store . createIndex ( "is_spec" "isSpec" , {
         unique:   false
    });
     store . createIndex ( "title" "title" , {
         unique:   false
    });
}
 
function   create ( store_n ) {
     db . createObjectStore ( store_n );
}
 
function   add ( store_n data ) {
     let   tran  =  db . transaction ( store_n mode ). objectStore ( store_n );
     data . forEach (( v =>  {
         tran . put ( v );
    })
     tran . oncomplete  = ( x =>  {
         console . log ( "add success" );
         console . log ( x );
    }
}
 
function   get ( store_n key value ) {
     //IDBKeyRange.only(value);
     return   new   Promise (( resolve =>  {
         let   index  =  db . transaction ( store_n mode ). objectStore ( store_n ). index ( key );
         let   result  =  index . getAll ( value );
         result . onsuccess  = ( x =>  {
             let   tmp  =  x . target . result ;
             if  ( tmp  &&  tmp  !=  null ) {
                 console . log ( tmp )
                 resolve ( tmp );
            }
        };
         result . onerror  = ( x =>  {
             console . log ( x );
        }
    });
}
 
export  {
     create ,
     add ,
     get ,
     mode
}
加载中
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部