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

I am using angularJS for my application it have bit completion in foreach loop. I created a JSON for following array.

Array
(
     [0] => Array
     (
        [0] => Array
            (
                [id] => 2
                [semester_id] => 1
                [dealer_id] => 120
     )
     [0] => Array
            (
                [id] => 2
                [semester_id] => 1
                [dealer_id] => 120
     )
    )
    [1] => Array
    (
        [0] => Array
            (
                [id] => 1
                [semester_id] => 2
                [dealer_id] => 255
    )
)

I want to generate this array json as like

<div id="1">
  <div>
    <span>id = 2,semeter id = 1, dealerid =120</span>
    <span>id = 2,semeter id = 1, dealerid =120</span>
  </div>
</div>
<div id="2">
  <div>
    <span>id = 2,semeter id = 1, dealerid =255</span>
  </div>
</div>

Can anyone please help on this

I tried this Actually i am using Codeigniter framework with this

app.js

app.controller('dashboard', function($scope, $http) {
  dashboard_home(); // Load all available tasks 
    function dashboard_home(){  
      $http.post(base_url+"admin/dashboard").success(function(data){
        $scope.dashboard = data[0];
    });
  };
});

I am returning json data from codeigniter controller to view. I used ng-repeat but i am result like

<div>
    <span>id = 2,semeter id = 1, dealerid =120</span>
    <span>id = 2,semeter id = 1, dealerid =120</span>
</div>

two times i am getting this only. I am not getting this div

<div>
    <span>id = 2,semeter id = 1, dealerid =255</span>
</div> 
share|improve this question
    
@MarcinNabiałek i have edited my question with my tried code – Arun Jul 21 '14 at 6:38
up vote 0 down vote accepted

Update: Is your issue getting the data?

$scope.dashboard = data.data; // maybe data.data[0] as per your code.

might be the correct format but you can always put a break point in your JavaScript code and watch how deep your real data goes in the response.

This looks fairly straight forward to me. Here is the HTML

<div ng-repeat="val in array" id="{{$index+1}}">
    <div>
        <span ng-repeat="val2 in val" >
            id = {{val2.id}},semeter id = {{val2.semester_id}},
             dealerid ={{val2.dealer_id}}
        </span>
    </div>
</div>

I am assuming the correct structure is this

Array
(
     [0] => Array
     (
        [0] => Array
            (
                [id] => 2
                [semester_id] => 1
                [dealer_id] => 120
            )
        [1] => Array
            (
                [id] => 2
                [semester_id] => 1
                [dealer_id] => 120
             )
    )
    [1] => Array
    (
        [0] => Array
            (
                [id] => 1
                [semester_id] => 2
                [dealer_id] => 255
            )
     )
)
share|improve this answer
    
Thank You it works – Arun Jul 22 '14 at 6:47

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.