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
            }, 
          });
    

      

  • 相关阅读:
    streamreader
    python编码问题总结
    linux rz上传文件及出错解决方案
    使用linux远程登录另一台linux
    利用Django实现RESTful API(一)
    windows下搭建vue开发环境
    windows下python虚拟环境virtualenv安装和使用
    SonarQube的安装、配置与使用
    windows下安装Mysql(图文详解)
    静态代码分析工具sonarqube+sonar-runner的安装配置及使用
  • 原文地址:https://www.cnblogs.com/zhangtianqi520/p/9323827.html
Copyright © 2011-2022 走看看