Angular js父子数据插入数组

时间:2016-02-04 06:15:57

标签: angularjs

当我从数据库中获取父子数据时,我遇到了一些问题。 我需要使用for each loop通过所有数据插入一个数组列表..我做了一些编码......

从数据库中获取数据的我的角度js代码是:

    $scope.fecthContent = function () {
        $http.get("/api/Permission/Menus").success(function (data) {
            debugger;
            $scope.lists = data;
            $scope.lists.splice(0, 1);//removing first row 
            angular.forEach($scope.lists, function (data, index) {
                $scope.list = data;
                angular.forEach($scope.list.child, function (c, index) {
                    $scope.list.child.push(c);
                    //$scope.States.push(states);
                });
            });
        });
    };
    $scope.fecthContent();

我的$scope.lists对象:

 $scope.list = {
        "menu_id": "",
        "menu_text": "",
        "url": "",
        "menu_code": "",
        "level": "",
        "parent_menu_id": "",
        "audit_user_id": "",
        "audit_ts": "",
        "sort": "",
        "IsRead": true,
        "IsWrite": "",
        "IsDelete":"",
        "child":[]
    }

我的数据库数据如下所示:

{
"_id" : ObjectId("56a072d53599d619f416236a"),
"menu_id" : "2",
"menu_text" : "Sales & Quotation",
"url" : "",
"menu_code" : null,
"level" : "0",
"parent_menu_id" : "0",
"audit_user_id" : 0,
"audit_ts" : ISODate("2016-01-21T05:55:32.704Z"),
"sort" : 1,
"icon" : null,
"child" : [ 
    {
        "_id" : ObjectId("000000000000000000000000"),
        "menu_id" : "2.1",
        "menu_text" : "Direct Sales",
        "url" : "/DirectSales",
        "menu_code" : null,
        "level" : "2",
        "parent_menu_id" : "2",
        "audit_user_id" : 0,
        "audit_ts" : ISODate("2016-01-21T06:04:39.160Z"),
        "sort" : 1,
        "icon" : null,
        "child" : [ 
            {
                "_id" : ObjectId("000000000000000000000000"),
                "menu_id" : "2.1.1",
                "menu_text" : "Direct Sales test",
                "url" : "/DirectSalestest",
                "menu_code" : null,
                "level" : "2",
                "parent_menu_id" : "2.1",
                "audit_user_id" : 0,
                "audit_ts" : ISODate("2016-01-21T07:30:15.652Z"),
                "sort" : 1,
                "icon" : null,
                "child" : []
            }, 
            {
                "_id" : ObjectId("000000000000000000000000"),
                "menu_id" : "2.1.2",
                "menu_text" : "test",
                "url" : "/test",
                "menu_code" : null,
                "level" : "2",
                "parent_menu_id" : "2.1",
                "audit_user_id" : 0,
                "audit_ts" : ISODate("2016-01-21T08:52:41.558Z"),
                "sort" : 2,
                "icon" : null,
                "child" : []
            }
        ]
    }, 

我希望数据看起来像this

0 个答案:

没有答案