简体   繁体   中英

Object map with links to other object

how do i link object that i use to other object values? right now im trying and im getting undefined any ways to link them so i can add 1 to persons code?

    @action getData(name, code) {
    const { john, mark, kyle, joe } = this.stats;
    const statMap = {
        joseph: john[code],
        markus: mark[code],
        adwsw: kyle[code],
        Joseph: joe[code],
    };
    function addOne() {
        console.log(joe) // normal
        statMap[name] += 1;
        console.log(statMap[name]) // NaN
    }
    return addOne();
}

adding console.log(JSON.stringify(this.stats));

{"joe":{"name":"Joseph","12421":88,"24352":114},"mark": 
{"name":"mark","4511":20,"5123":64},"john":{"name":"joseph 
%","155511":38,"5254332":62},"kyle":{"name":"kyle","151":7,"2":12}}

found the solution :

 @action getData(name, code) {
     if(('mark joe joseph kyle').includes(name)){
           this.stats[name][code] += 1;
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM