网站
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

114 lines
2.1 KiB

  1. /*!
  2. * @module 无限极下拉框
  3. * 2022-2-9
  4. * by 庞东旭
  5. */
  6. let array = [];
  7. let childrenArray = [];
  8. function InfinitePullDown(boxId,data){
  9. $('' + boxId + ' > select').change(function () {
  10. const index = $('' + boxId + ' > select').index(this) + 1;
  11. const selectLength = $(boxId).children('select').length;
  12. let id = $(this).val();
  13. console.log(index+'-----------------'+selectLength)
  14. if (index == 1){
  15. childrenArray = data ;
  16. }
  17. forArray(childrenArray,index,id)
  18. if (index < selectLength){
  19. for (let i = index ; i < selectLength ; i++){
  20. $($(boxId).find("select")[i].remove());
  21. }
  22. }
  23. // if (index == 1){
  24. array = eval(data).filter(function (e) {
  25. return e.id == id;
  26. })
  27. // }else{
  28. //
  29. // childrenArray = eval(childrenArray[0].children).filter(function (e) { return e.id == id; })
  30. //
  31. // }
  32. console.log(childrenArray)
  33. addArray(boxId,array[0])
  34. })
  35. };
  36. function addArray(boxId,data){
  37. if (data.children.length>0){
  38. var options = '';
  39. for (var i = 0 ; i < data.children.length ; i++){
  40. options += '<option value="' + data.children[i].id + '">' + data.children[i].classificationName + '</option>' ;
  41. }
  42. $(boxId).append(
  43. '<select style="width: 49%;">' +
  44. options +
  45. '</select>'
  46. )
  47. InfinitePullDown('#projectContent',data.children)
  48. }
  49. };
  50. let num = 0;
  51. function forArray(data,index,id){
  52. num++;
  53. let temporaryData = [];
  54. if (num == index){return;}
  55. temporaryData = eval(data).filter(function (e) { return e.id == id; });
  56. for (let i = 0 ; i < data.length ; i++){
  57. console.log(temporaryData.length)
  58. console.log(data)
  59. if (temporaryData.length == 0){
  60. forArray(data[i].children,index,id)
  61. }else{
  62. temporaryData = eval(data).filter(function (e) { return e.id == id; });
  63. return;
  64. }
  65. console.log(temporaryData)
  66. // forArray(array,index);
  67. }
  68. }