具有指向其他对象链接的对象图

时间:2019-03-04 10:35:40

标签: javascript object mobx

如何将使用的对象链接到其他对象值? 现在我正在尝试并且我未定义任何将它们链接的方法,因此我可以在人员代码中添加1?

    @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();
}

添加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}}

1 个答案:

答案 0 :(得分:0)

找到了解决方法:

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