zoukankan      html  css  js  c++  java
  • 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
            }, 
          });
    

      

  • 相关阅读:
    [比赛|考试]9.21上午考试
    给花_Q
    [比赛|考试] 9.17下午考试
    [比赛|考试]nowcoder NOIP提高组组第二场
    图论
    生成函数
    P4197 Peaks
    3942: [Usaco2015 Feb]Censoring
    P2245 星际导航
    P3565 [POI2014]HOT-Hotels
  • 原文地址:https://www.cnblogs.com/zhangtianqi520/p/9323827.html
Copyright © 2011-2022 走看看