util.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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, compare) {
  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], compare);
  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. if (compare) {
  35. arr.sort(compare);
  36. } else {
  37. arr.sort();
  38. }
  39. for(let a of arr){
  40. newOjb[a]= sortJson(obj[a], compare);
  41. }
  42. return newOjb;
  43. }else {
  44. return obj;
  45. }
  46. }