util.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Created by zhang on 2018/9/11.
  3. */
  4. async function initCompilationSelect() {
  5. try {
  6. $('#compilationSels').empty();
  7. let result = await ajaxPost("/stdBillsEditor/getCompilationList");
  8. for(let r of result){
  9. let $option = $("<option >"+r.name +"</option>");
  10. $option.val( r._id);
  11. $('#compilationSels').append($option);
  12. }
  13. }catch (err){
  14. alert("取编办信息有误");
  15. console.log(err)
  16. }
  17. }
  18. //对JSON对象排序,按属性key的顺序显示
  19. function sortJson(obj) {
  20. if(obj === null){
  21. return null;
  22. }
  23. if(obj instanceof Array){
  24. for(let o in obj){
  25. obj[o] = sortJson(obj[o]);
  26. }
  27. return obj;
  28. }else if(typeof obj == 'object'){
  29. let arr=[];
  30. let newOjb ={};
  31. for(let key in obj){
  32. arr.push(key);
  33. }
  34. arr.sort();
  35. for(let a of arr){
  36. newOjb[a]= sortJson(obj[a]);
  37. }
  38. return newOjb;
  39. }else {
  40. return obj;
  41. }
  42. }