Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am a newbie to angular js.This might be a piece of cake for many of you. Could you please guide me? I have a json file, a view to display, index.html(view), and a controller(index_angular.js).In the image the second and third columns are drop down menus corresponding to the technology id in json.

How to parse the json and display in the view according to the image as its attached.

Thanks in advance.

JSON STRUCTURE:

{
    "technology": [
        {
            "id": "AKC",
            "detail": {
                "drop1": [
                    {
                        "id": "AKC-lst-1231"
                    },
                    {
                        "id": "AKC-lst-1232"
                    },
                    {
                        "id": "AKC-lst-1233"
                    }
                ],
                "drop2": [
                    {
                        "id": "T_AKC_live"
                    },
                    {
                        "id": "T_AKC_Capt"
                    },
                    {
                        "id": "T_AKC_live1"
                    }
                ]
            }
        },
        {
            "id": "MET",
            "detail": {
                "drop1": [
                    {
                        "id": "MET-2st"
                    },
                    {
                        "id": "MET-34"
                    }
                ],
                "drop2": [
                    {
                        "id": "sd-232"
                    },
                    {
                        "id": "sd-121"
                    }
                ]
            }
        }
    ]
}

Required Format to display in view in Angular JS:

Coloumn 2 and coloumn 3 are drop down menus of drop1 and drop2 of corresponding technology id

enter image description here

index_angular.js(CONTROLLER)

var myModule=angular.module('test',[]);
myModule.controller("test_controller", function($scope,$http){
            $scope.message = "hello world!";
            $scope.posts = "";
            $scope.init=function(){

            $scope.friends = ["Test friends","test1","test2","test4","test5","test6","test7","test8","test9","test10","test11","test12","test13","test113","test14","test114","test15","test133","test23","test33","test35"];


            $http.get("test.json").
            success(function(data, status, headers, config) {
            $scope.posts = data;
            alert($scope.posts);
            $scope.tech_name=[];
            $scope.technology="";
            console.log($scope.posts);
            var tech_marker_count= $scope.posts.technology.length;
            alert(tech_marker_count);//count of technology

            for(var tech_marker=0;tech_marker<tech_marker_count;tech_marker++)
            {
             $scope.tech_name.push($scope.posts.technology[tech_marker].id);
             $scope.technology=$scope.posts.technology[tech_marker].id;
             alert( $scope.technology);
            }

            }).
            error(function(data, status, headers, config) {
            alert("Error fetching data");
      // log error
    });

};      
        });

index.html(VIEW)

 <div class="view_data"> 
       <ul>

       </ul>
  </div>
share|improve this question
    
Have you tried doing smth? docs.angularjs.org/api/ng/directive/ngRepeat – user854301 Feb 26 at 10:00
    
know the basic usage of it but I am not much aware of using it this type of complicated JSON parsing data and displaying it in the view at parsing time – Rajeshwar Feb 26 at 10:43

1 Answer 1

You can take use of ng-repeat that does help you to loop through the json

Your html will look like below,

HTML

  <div class="view_data" ng-init="init()"> 
       <div ng-repeat="d in posts.technology|orderBy: 'id'">
         {{d.id}}
         |<span ng-repeat="drop1Item in d.detail.drop1">{{drop1Item.id}}</span>
         |<span ng-repeat="drop2Item in d.detail.drop2">{{drop2Item.id}}</span>
       </div>
  </div>

Working Plunkr need some styling on it.

Now its turn to do design. Thanks.

share|improve this answer
    
Does it help you? – Pankaj Parkar Mar 2 at 12:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.