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

      

  • 相关阅读:
    Python随笔,day1
    利用php抓取蜘蛛爬虫痕迹的示例代码
    explain(执行计划)工具使用
    MyISAM和 InnoDB中索引的数据结构
    页面静态化技术(真静态和伪静态的实现)
    关于MySQL字符集和校对集问题
    客户端禁用cookie后session的解决方法
    解决Ajax中的缓存问题
    MySQL中列类型的选择需要注意的问题
    MySQL中索引的分类和基本操作
  • 原文地址:https://www.cnblogs.com/zhangtianqi520/p/9323827.html
Copyright © 2011-2022 走看看