Kaynağa Gözat

一些功能

Kirin 4 yıl önce
ebeveyn
işleme
1a7ed1904f
2 değiştirilmiş dosya ile 17 ekleme ve 14 silme
  1. 17 14
      app/api/controller/PublicController.php
  2. 0 0
      public/1.js

+ 17 - 14
app/api/controller/PublicController.php

@@ -34,31 +34,34 @@ class PublicController
     public function test()
     public function test()
     {
     {
         $province = SystemCity::where('level', 0)->select();
         $province = SystemCity::where('level', 0)->select();
-        $res = [];
+        $res = "var city = [";
         foreach ($province as $k => $v) {
         foreach ($province as $k => $v) {
-            $child = [];
+            $child = "";
             $citys = SystemCity::where('level', 1)->where('parent_id', $v['city_id'])->select();
             $citys = SystemCity::where('level', 1)->where('parent_id', $v['city_id'])->select();
-//            var_dump($citys);
-//            var_dump($v['id']);
             if (count($citys)) {
             if (count($citys)) {
+                $child = ", children: [";
                 foreach ($citys as $kk => $vv) {
                 foreach ($citys as $kk => $vv) {
-                    $childs = [];
+                    $childs = "";
                     $dictres = SystemCity::where('level', 2)->where('parent_id', $vv['city_id'])->select();
                     $dictres = SystemCity::where('level', 2)->where('parent_id', $vv['city_id'])->select();
-//                    var_dump($dictres);
                     if (count($dictres)) {
                     if (count($dictres)) {
+                        $childs = ", children: [";
                         foreach ($dictres as $kkk => $vvv) {
                         foreach ($dictres as $kkk => $vvv) {
-                            $ress = ['value' => $kkk + 1, 'label' => $vvv['name']];
-                            $childs[] = $ress;
+                            $ress = $kkk == 0 ? ("{value: " . ($kkk + 1) . "}, label: '{$vvv['name']}'}") : (",{value: " . ($kkk + 1) . "}, label: '{$vvv['name']}'}");
+//                            $ress = ['value' => $kkk + 1, 'label' => $vvv['name']];
+                            $childs .= $ress;
                         }
                         }
+                        $childs .= "]";
                     }
                     }
-                    $ress = ['value' => $kk + 1, 'label' => $vv['name']];
-                    if (count($childs)) $ress = array_merge($ress, ['children' => $childs]);
-                    $child[] = $ress;
+                    $ress = $kkk == 0 ? ("{value: " . ($kkk + 1) . "}, label: '{$vvv['name']}'") : (",{value: " . ($kkk + 1) . "}, label: '{$vvv['name']}'");
+                    if ($childs) $ress .= ',' . $childs;
+                    $ress .= '}';
+                    $child .= $ress;
                 }
                 }
+                $child .= "]";
             }
             }
-            $ress = ['value' => $k + 1, 'label' => $v['name']];
-            if (count($child)) $ress = array_merge($ress, ['children' => $child]);
-            $res[] = $ress;
+            $ress = $kkk == 0 ? ("{value: " . ($kkk + 1) . "}, label: '{$vvv['name']}'") : (",{value: " . ($kkk + 1) . "}, label: '{$vvv['name']}'");
+            if ($child) $ress .= ',' . $child;
+            $res .= $ress;
         }
         }
         var_dump($res);
         var_dump($res);
     }
     }

+ 0 - 0
public/1.js