ich habe:mongodb/JavaScript-Variable in Abfrage
var optiontable = {1: 'attack', 2: 'defence', 3: 'intelligence'};
var option = 1;
var minion = minions[thisminion]; // get correct, works.
console.log(optiontable[option]); // would output "attack"
var nameoption = optiontable[option];
var increasement = 8;
wie würde ich die minion.attack zu erhalten tun, um auf Basis von:
thisminion.nameoption // this wont work when it should display the result of thisminion.attack
und erhalten die nameoption in verwenden:
minions.update({
_id: thisminion._id,
userid: playerid
}, {$inc: {nameoption: increasement}})
aber thisminion.attack ist der richtige. Ich brauche es, um mit der Variable zu arbeiten. – maria
Ich habe meine Antwort aktualisiert, nachdem ich Ihre Frage erneut gelesen habe. Das tut mir leid. – Maksym