问题
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