zoukankan      html  css  js  c++  java
  • JavaScript将字典序升序排列类似php中的ksort函数

    /**
      * 将json数据进行排序
      * @param {*jason} data 
      */
     export function JsonSort(jsonData) {
      try {
        let tempJsonObj = {};
        let sdic = Object.keys(jsonData).sort();
        sdic.map((item, index)=>{
          tempJsonObj[item] = jsonData[sdic[index]]
        })
        console.log('将返回的数据进行输出',tempJsonObj);
        return tempJsonObj;
      } catch(e) {
        return jsonData;
      }
    }
    

        

      

    示例代码
    function JsonSort(jsonData) {
      try {
        let tempJsonObj = {};
        let sdic = Object.keys(jsonData).sort();
        sdic.map((item, index)=>{
          tempJsonObj[item] = jsonData[sdic[index]]
        })
        return tempJsonObj;
      } catch(e) {
        return jsonData;
      }
    }
    let tempJson = {"BopicId": "142","Appid": "100002","Ein": "system","Din": "dsadasd"}
    JsonSort(tempJson);

    效果图

  • 相关阅读:
    鼠标移入图片放大效果
    搜索框
    将下拉菜单放入input框中
    轮播图2
    V-demo item.vue
    v-demo1 List.vue
    v-demo1 add.vue
    v-demo1 app.vue
    3D轮播图
    封装代码
  • 原文地址:https://www.cnblogs.com/ChineseLiao/p/10150727.html
Copyright © 2011-2022 走看看