• echarts设置option中的数据对象优化


    if(tab.name == 'first'){
              myChart.setOption({
                legend: {
                selected:{
                  [this.playNumber]:true,
                  [this.coverNumber]:false,
                  [this.touchNumber]:false,
                  [this.winPrizeNum]:false,
                  [this.takePrizeNum]:false
                }
            },
    
              })
          }else if(tab.name == 'second'){
              myChart.setOption({
                legend: {
                  selected:{
                  [this.playNumber]:false,
                  [this.coverNumber]:true,
                  [this.touchNumber]:false,
                  [this.winPrizeNum]:false,
                  [this.takePrizeNum]:false
                 }
                },  
              })
          }else if(tab.name == 'third'){
              myChart.setOption({
                legend: {
                  selected:{
                    [this.playNumber]:false,
                    [this.coverNumber]:false,
                    [this.touchNumber]:true,
                    [this.winPrizeNum]:false,
                    [this.takePrizeNum]:false
                  }
                },  
              })
          }else if(tab.name == 'fourth'){
              myChart.setOption({
                legend: {
                  selected:{
                    [this.playNumber]:false,
                    [this.coverNumber]:false,
                    [this.touchNumber]:false,
                    [this.winPrizeNum]:true,
                    [this.takePrizeNum]:false
                  }
                }   
              })
          }else if(tab.name == 'five'){
              myChart.setOption({
                legend: {
                  selected:{
                    [this.playNumber]:false,
                    [this.coverNumber]:false,
                    [this.touchNumber]:false,
                    [this.winPrizeNum]:false,
                    [this.takePrizeNum]:true
                  }
                }
              })
          }
    

      代码优化:

    var arr = {'first':[this.playNumber],'second':[this.coverNumber],'third':[this.touchNumber],'fourth':[this.winPrizeNum],'five':[this.takePrizeNum]};
          var obj = {
              [this.playNumber]:false,
              [this.coverNumber]:false,
              [this.touchNumber]:false,
              [this.winPrizeNum]:false,
              [this.takePrizeNum]:false
          };
          Object.keys(arr).forEach(function(key){
            if(tab.name == key){
              obj[arr[key]] = true;
            }
          });
          myChart.setOption({
            legend: {
              selected: obj
            }, 
          });
    

      

  • 相关阅读:
    luogu P3238 [HNOI2014]道路堵塞
    luogu P3235 [HNOI2014]江南乐
    luogu P3237 [HNOI2014]米特运输
    luogu P3233 [HNOI2014]世界树
    luogu P3234 [HNOI2014]抄卡组
    luogu P3250 [HNOI2016]网络
    luogu P3201 [HNOI2009]梦幻布丁
    luogu P4148 简单题
    luogu P3767 膜法
    luogu P4314 CPU监控
  • 原文地址:https://www.cnblogs.com/zhangtianqi520/p/9323827.html
Copyright © 2020-2023  润新知