0

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> 
1
  • @MarcinNabiałek i have edited my question with my tried code Commented Jul 21, 2014 at 6:38

1 Answer 1

0

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
            )
     )
)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.