【问题标题】:Convert Ajax value to Another State将 Ajax 值转换为另一种状态
【发布时间】:2017-10-03 09:50:27
【问题描述】:

我花了几个小时寻求帮助,从 json 编码返回另一个文本 ini 脚本。我有一个带有值的 Json_Encode 输出

[
{"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,
                }]
            }; 

而我在 labels: sta, 中的标签是输出 [1,2,3,6]

但我想在我们使用 php 时将该输出转换为另一种状态

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"; }

我的问题是如何像在 PHP 中那样在 Javascript ajax 中进行转换?
我的预期值是在更改值后但我不知道如何更改值 ini 脚本
标签为输出['Application','Process,Staff','Validation','Done']
需要帮助大师 我是php初学者

【问题讨论】:

    标签: php mysql ajax getjson


    【解决方案1】:

    我认为你应该创建这样的转换状态的方法

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

    你在推送到数组之前调用方法

    sta.push(convertStatus(data[i].status_ppid));
    

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多