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

      

  • 相关阅读:
    学生管理系统初步总结
    ListView控件详解
    Windows窗体应用布局详解
    winforms控件
    指尖上的数据库之探囊取物
    指尖上的数据库之无中生有
    银行bank系统项目实践
    QT Creator 快速入门教程 读书笔记(一)
    我的程序员之路(英语的学习)
    游戏开发完整学习路线(各个版本都有)
  • 原文地址:https://www.cnblogs.com/zhangtianqi520/p/9323827.html
Copyright © 2011-2022 走看看