dongyingming8970 2017-05-05 03:32
浏览 34
已采纳

将Ajax值转换为另一个状态

I have spent hours looking for help with returning to another text ini script from json encode. I have a Json_Encode output with value

[
{"JumStatus":3,"status_ppid":"1"},
{"JumStatus":4,"status_ppid":"2"},
{"JumStatus":1,"status_ppid":"3"},
{"JumStatus":1,"status_ppid":"6"}
]

url: "_DEFINE_GET/_GetData.php",
        method: "GET",
        success: function(data) {
            console.log(data);

            var sta = [];
            var jum = [];
            for(var i in data) {
                sta.push(data[i].status_ppid);
                jum.push(data[i].JumStatus);
            }
         var chartdata = {
                labels: sta,
                datasets: [{
                    backgroundColor: [
                        "#2ecc71",
                        "#f1c40f",
                        "#3498db",
                        "#ff5722",
                        "#34495e",
                        '#009688',
                        "#e91e63"
                    ],
                    hoverBackgroundColor: [
                        'rgba(0,255,0,0.3)',
                        'rgba(255,255,0,0.3)',
                        'rgba(0,0,255,0.3)',
                        'rgba(255,0,0,0.3)',
                        'rgba(192,192,192,0.6)',
                        'rgba(42,176,99,0.63)',
                        'rgba(255,0,0,0.3)',
                    ],
                    data: jum,
                }]
            }; 

And my label in labels: sta, is output [1,2,3,6]

But i want to convert that output to another state when in php we use

if      ($status_ppid=="1" ) { $status_ppid=="Application"; }
elseif  ($status_ppid=="2" ) { $status_ppid=="Proccess"; }
elseif  ($status_ppid=="3" ) { $status_ppid=="Staff Validation"; }
elseif  ($status_ppid=="4" ) { $status_ppid=="Analys Validation"; }
elseif  ($status_ppid=="5" ) { $status_ppid=="Manager Validation"; }
elseif  ($status_ppid=="6" ) { $status_ppid=="Done"; }

And my question how to convert like that in Javascript ajax like in PHP?
My Expected value is after change the value but i dont know how to change the value ini script
label is output ['Application','Proccess,Staff','Validation','Done']
Need Help master I am beginner in php

  • 写回答

1条回答 默认 最新

  • duanpiyao2734 2017-05-05 04:05
    关注

    I think you should create method for convert status like this

    function convertStatus(id) {
       var status = "";  
       if (id == '1') {
          status = "Application";
       } else if (id == '2') {
          status = "Proccess";
       } else if (id == '3'){ 
          status = "Staff Validation";
       } else if (id == '4'){ 
          status = "Analys Validation";
       } else if (id == '5'){ 
          status = "Manager Validation";
       } else if (id == '6'){ 
          status = "Done";
       }
       return status;
    }
    

    And you call the method before push to array

    sta.push(convertStatus(data[i].status_ppid));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)