假设我有以下mysql表。不同的副总裁,每个都有自己的董事,高级管理人员,经理和员工名单。我需要创建一个带有层次结构的对象来绑定我的flex应用程序中的所有下拉列表。我需要一种动态的方法来迭代和创建对象内的对象数组。现在我可以做一堆for循环并让它工作,但是它给了我一个要求它应该足够灵活,以便在添加新层时(例如SrSagersrs上面的SuperSeniorManagers)。它应该能够检测和调整。我有一个单独的表,我存储不同的层次结构级别,我可以在创建对象时将其用作参考。如;
我似乎无法创建一个可以执行此操作的函数,而无需每次都修改代码。我正在使用actionscript,但是如果你的解决方案是javascript也应该没问题。非常感谢任何帮助!
+----------------+-----------+------------+-----------+------------+
| VPs | Directors | SrManagers | Managers | Employees |
+----------------+-----------+------------+-----------+------------+
| VP1 | Director1 | SrManager1 | Manager1 | Employee1 |
| VP1 | Director1 | SrManager1 | Manager1 | Employee2 |
| VP1 | Director1 | SrManager1 | Manager1 | Employee3 |
| VP1 | Director1 | SrManager1 | Manager2 | Employee4 |
| VP1 | Director1 | SrManager1 | Manager2 | Employee5 |
| VP1 | Director1 | SrManager2 | Manager3 | Employee6 |
| VP1 | Director1 | SrManager2 | Manager3 | Employee7 |
| VP1 | Director1 | SrManager2 | Manager3 | Employee8 |
| VP1 | Director1 | SrManager2 | Manager3 | Employee9 |
| VP1 | Director2 | SrManager3 | Manager4 | Employee10 |
| VP1 | Director2 | SrManager3 | Manager4 | Employee11 |
| VP1 | Director2 | SrManager3 | Manager4 | Employee12 |
| VP1 | Director2 | SrManager4 | Manager5 | Employee13 |
| VP1 | Director2 | SrManager4 | Manager5 | Employee14 |
| VP1 | Director2 | SrManager4 | Manager6 | Employee15 |
| VP2 | Director3 | SrManager5 | Manager7 | Employee16 |
| VP2 | Director3 | SrManager5 | Manager7 | Employee17 |
| VP2 | Director3 | SrManager5 | Manager8 | Employee18 |
| VP2 | Director3 | SrManager5 | Manager8 | Employee19 |
| VP2 | Director3 | SrManager5 | Manager8 | Employee20 |
| VP2 | Director3 | SrManager6 | Manager9 | Employee21 |
| VP2 | Director3 | SrManager6 | Manager10 | Employee22 |
| VP2 | Director3 | SrManager7 | Manager11 | Employee23 |
| VP2 | Director3 | SrManager7 | Manager11 | Employee24 |
| VP2 | Director3 | SrManager7 | Manager11 | Employee25 |
| VP2 | Director4 | SrManager8 | Manager12 | Employee26 |
| VP2 | Director4 | SrManager9 | Manager13 | Employee27 |
+----------------+-----------+------------+-----------+------------+