Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:在ng repeat中从php输出数组(带键)?_Javascript_Php_Arrays_Angularjs - Fatal编程技术网

Javascript AngularJS:在ng repeat中从php输出数组(带键)?

Javascript AngularJS:在ng repeat中从php输出数组(带键)?,javascript,php,arrays,angularjs,Javascript,Php,Arrays,Angularjs,我有一个rootScope变量,它将包含产品的类别,每个类别可能有子类别,也可能没有子类别。这就是我分配根范围的方式: $rootScope.categoryList = $http.get('category').then((result) -> result.data) 这将请求(向Laravel route)获取类别数据数组,数据的设计如下所示: $data = array( {category: Category, children: array('child1

我有一个
rootScope
变量,它将包含产品的类别,每个类别可能有子类别,也可能没有子类别。这就是我分配
根范围的方式:

$rootScope.categoryList = $http.get('category').then((result) -> result.data) 
这将请求(向Laravel route)获取类别数据数组,数据的设计如下所示:

$data = array(
        {category: Category, children: array('child1, child2, child3')},
        {category: Category2, children: null},
        {category: Category3, children: array('anotherchild1, anotherchild2')}
    );
<li ng-repeat="cat in categoryList">
                {{cat.category}}
            </li>
我生成数组的方式如下:

public static function GetCategoryListings($ignore=false) {
    $results = DB::table('category')->where('parent','-')->get();
    $data = array();

    if(!is_null($results)) {
        $i = 0;
        foreach($results as $result) {
            $data[$i]['category'] = $result;
            $child_result = DB::table('category')->where('parent',$result)->get();

            if(!is_null($child_result)) {
                foreach($child_result as $child) {
                    $data[$i]['children'][] = $child;
                }
            }
            else
                $data[$i]['children'] = null;

            $i++;
        }
    }
    return $data;
}
现在,我想将我的输出以角度打印到视图中,我将如何做到这一点?我做的 大概是这样的:

$data = array(
        {category: Category, children: array('child1, child2, child3')},
        {category: Category2, children: null},
        {category: Category3, children: array('anotherchild1, anotherchild2')}
    );
<li ng-repeat="cat in categoryList">
                {{cat.category}}
            </li>
  • {{cat.category}
  • 但它不起作用,而且我无法输出孩子们。这有什么办法吗

    编辑

    在我看来,通过改成这样的方式解决了我的问题:

    <ul>
                <li ng-repeat="cat in categoryList">
                    {{cat.category}}
                    <ul ng-if="cat.children != null">
                        <li ng-repeat="ch in cat.children">{{ch}}</li>
                    </ul>
                </li>
            </ul>
    
    • {{cat.category}
      • {{ch}

    这里可能有很多不同的问题,但很可能就是这样

    角度1.2。您必须将语法更改为以下内容:

    $http.get('category')。然后((结果)->$rootScope.categoryList=result.data)
    
    请记住,如果你依赖于
    categoryList
    作为承诺,这可能会破坏你应用程序中的其他内容