Is it possible to use square bracket notion in class methods?

谁说胖子不能爱 提交于 2020-01-25 04:19:48

问题


I am trying to automate running some queries with dexiejs but i can get them to work when i create a JavaScript function.

The queries simply don't run...

if i want to update i get:

Promise.js:840 Unhandled rejection: TypeError: Cannot read property 'update' of undefined

And the rest of my functionalities i.e delete follow the same path

i wrote a simple jsfiddle to demostrate my problem

<!doctype html>
<html>
  <head>
      <!-- Include Dexie -->
      <script src="https://unpkg.com/dexie@latest/dist/dexie.js"></script>

      <script>
      var db = new Dexie("MyFriendDB");
db.version(1).stores({
    friends: '++id,name,age'
});
db.friends.put({
        name: 'Camilla',
        age: 25 })
    .then(()=>{
    test(db,'friends' )
    });


function test(db,database_name){
//original : db.database_name.delete(1)
db[database_name[delete(1)]] //doesnt run
db.database_name.update(1, {name:"Alex"}).then(()=>{
console.log('success'); //also doesnt run
})
.catch(err=>{console.log(err)});
}
 db.friends.each(result=>{
console.log(result)
})


      </script>
  </head>
</html>

来源:https://stackoverflow.com/questions/59220777/is-it-possible-to-use-square-bracket-notion-in-class-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!