zoukankan      html  css  js  c++  java
  • js string类型转换成数组对象类型---eval

    js string类型转换成数组对象类型

    eval

    该方法只接受原始字符串作为参数,如果 string 参数不是原始字符串,那么该方法将不作任何改变地返回。因此请不要为 eval() 函数传递 String 对象来作为参数。

     插件原始数据

    /*const data = [
    { time: "00:00", value: 80 },
    { time: '06:00', value: 70 },
    { time: '12:00', value: 120 },
    { time: '18:00', value: 90 },
    { time: '24:00', value: 168 }
    ];*/

    后台的数据
    const trainingData = () => {
    return builder([{
    'training': {
    'xaxis': ['00:00', '06:00', '12:00', '18:00', '24:00'],
    'data': [0, 30, 45, 60, 30]
    }
    }])
    }


    拼接的字符串:[{time:"00:00",value:0},{time:"00:00",value:0},{time:"06:00",value:30},{time:"12:00",value:45},{time:"18:00",value:60},{time:"24:00",value:30},{time:"24:00",value:30}]
    TrainingStatus.vue?4f97:199 最后的结果数据[{time:"00:00",value:0},{time:"00:00",value:0},{time:"06:00",value:30},{time:"12:00",value:45},{time:"18:00",value:60},{time:"24:00",value:30},{time:"24:00",value:30}]
    TrainingStatus.vue?4f97:200 数据类型string
    TrainingStatus.vue?4f97:196 拼接的字符串:[{time:"00:00",value:0},{time:"00:00",value:0},{time:"06:00",value:30},{time:"12:00",value:45},{time:"18:00",value:60},{time:"24:00",value:30},{time:"24:00",value:30}]
    TrainingStatus.vue?4f97:199 最后的结果数据[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
    TrainingStatus.vue?4f97:200 数据类型object

     created () {
        getRoleList({ t: new Date() })
        getTrainingData().then(res => {
          this.trainingdata = res.data[0].training
          //心率折线数据
          for(var i =0 ; i<this.trainingdata.xaxis.length ; i++){
             var time1 = this.trainingdata.xaxis[i]
             var value1 = this.trainingdata.data[i]
            if(i==0){
              this.databinjie = '[{'+ 'time:"' +time1 + '",' + 'value:' +value1 + '},'
            }
             this.databinjie += '{'+ 'time:"' +time1 + '",' + 'value:' +value1 + '},'
            var changdu = this.trainingdata.xaxis.length -1
            if(i==changdu){
              this.databinjie += '{'+ 'time:"' +time1 + '",' + 'value:' +value1 + '}]'
            }
          }
          console.log('拼接的字符串:'+this.databinjie)
          this.data =  eval(this.databinjie)
          // this.data = JSON.parse(this.data)
          console.log('最后的结果数据'+this.data)
          console.log('数据类型'+typeof(this.data))
        })
      },
  • 相关阅读:
    spark编译
    使用MapReduce实现两个文件的Join操作
    响应式 Web 设计
    响应式 Web 设计
    900W+数据只用300ms搞定!SQL查询优化这样做最快耗时347ms
    响应式 Web 设计
    CSS3 多媒体查询实例
    CSS3 多媒体查询:查找设备的类型,CSS3 根据设置自适应显示
    CSS3 弹性盒子(Flex Box):确保元素拥有恰当的行为的布局方式
    CSS3 框大小:padding(内边距) 和 border(边框)
  • 原文地址:https://www.cnblogs.com/fdxjava/p/11611236.html
Copyright © 2011-2022 走看看