Angularjs and jquery.datatable with ui.bootstrap - need to show entries in json using a loop









up vote
0
down vote

favorite












I need to show the entries of the json in a loop.
I'm new in js and angular, and I don't know how to enter a for in the marked place of the code below.
I need to know to do all the code, this just a test for a larger project.



 <?php
$estudent=array(
"name" => "luis",
"age" => "10");
$estudent=array(
"name" => "maria",
"age" => "12");
$objJson=json_encode($estudent);
?>
//here is the js
<script>
var json=eval(<?php echo $objJson; ?>);
//Angularjs and jquery.datatable with ui.bootstrap and ui.utils

var app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
app.controller('validationCtrl',function($scope)

$scope.data = [
[ //i need to use a loop for show all the studens
json[0].name,
json[0].age,
],
[ //i need to use a loop for show all the studens
json[1].name,
json[1].age,
],
]

$scope.dataTableOpt =
//custom datatable options
// or load data through ajax call also
"aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
;
);
</script>









share|improve this question



























    up vote
    0
    down vote

    favorite












    I need to show the entries of the json in a loop.
    I'm new in js and angular, and I don't know how to enter a for in the marked place of the code below.
    I need to know to do all the code, this just a test for a larger project.



     <?php
    $estudent=array(
    "name" => "luis",
    "age" => "10");
    $estudent=array(
    "name" => "maria",
    "age" => "12");
    $objJson=json_encode($estudent);
    ?>
    //here is the js
    <script>
    var json=eval(<?php echo $objJson; ?>);
    //Angularjs and jquery.datatable with ui.bootstrap and ui.utils

    var app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
    app.controller('validationCtrl',function($scope)

    $scope.data = [
    [ //i need to use a loop for show all the studens
    json[0].name,
    json[0].age,
    ],
    [ //i need to use a loop for show all the studens
    json[1].name,
    json[1].age,
    ],
    ]

    $scope.dataTableOpt =
    //custom datatable options
    // or load data through ajax call also
    "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
    ;
    );
    </script>









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I need to show the entries of the json in a loop.
      I'm new in js and angular, and I don't know how to enter a for in the marked place of the code below.
      I need to know to do all the code, this just a test for a larger project.



       <?php
      $estudent=array(
      "name" => "luis",
      "age" => "10");
      $estudent=array(
      "name" => "maria",
      "age" => "12");
      $objJson=json_encode($estudent);
      ?>
      //here is the js
      <script>
      var json=eval(<?php echo $objJson; ?>);
      //Angularjs and jquery.datatable with ui.bootstrap and ui.utils

      var app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
      app.controller('validationCtrl',function($scope)

      $scope.data = [
      [ //i need to use a loop for show all the studens
      json[0].name,
      json[0].age,
      ],
      [ //i need to use a loop for show all the studens
      json[1].name,
      json[1].age,
      ],
      ]

      $scope.dataTableOpt =
      //custom datatable options
      // or load data through ajax call also
      "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
      ;
      );
      </script>









      share|improve this question















      I need to show the entries of the json in a loop.
      I'm new in js and angular, and I don't know how to enter a for in the marked place of the code below.
      I need to know to do all the code, this just a test for a larger project.



       <?php
      $estudent=array(
      "name" => "luis",
      "age" => "10");
      $estudent=array(
      "name" => "maria",
      "age" => "12");
      $objJson=json_encode($estudent);
      ?>
      //here is the js
      <script>
      var json=eval(<?php echo $objJson; ?>);
      //Angularjs and jquery.datatable with ui.bootstrap and ui.utils

      var app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
      app.controller('validationCtrl',function($scope)

      $scope.data = [
      [ //i need to use a loop for show all the studens
      json[0].name,
      json[0].age,
      ],
      [ //i need to use a loop for show all the studens
      json[1].name,
      json[1].age,
      ],
      ]

      $scope.dataTableOpt =
      //custom datatable options
      // or load data through ajax call also
      "aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
      ;
      );
      </script>






      javascript angularjs json for-loop






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 3:47









      dmcgrandle

      826215




      826215










      asked Nov 11 at 1:33









      Luis González

      83




      83






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          For this loop you can use:



          $scope.data = ;
          angular.forEach(json, (item) =>
          // here you can get item.age and item.name
          $scope.data.push(item);
          );


          At the end of this loop your $scope.data will have all students in it






          share|improve this answer




















          • didn't work, now show empty entries
            – Luis González
            Nov 11 at 3:44


















          up vote
          0
          down vote













          In my opinion your JSON is valid, try to change format of JSON for something similar to this :



           $scope.data = [
          "name": "json[0].name",
          "age": "json[0].age"
          ,

          "name": "json[1].name",
          "age": "json[1].age"

          ]


          Then you can easly console or show it



          angular.forEach($scope.data, function (value, index) 
          console.log($scope.data[index] + ' ' + index);
          );


          HTML



          <ul ng-repeat="json in data">
          <li><b>Name: </b> <p>json.name</p> <b>Age: </b> <p>json.age</p></li>
          </ul>


          plunker: http://plnkr.co/edit/s6ix8aEDz0jR3UeXGL6M?p=preview






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245090%2fangularjs-and-jquery-datatable-with-ui-bootstrap-need-to-show-entries-in-json%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            For this loop you can use:



            $scope.data = ;
            angular.forEach(json, (item) =>
            // here you can get item.age and item.name
            $scope.data.push(item);
            );


            At the end of this loop your $scope.data will have all students in it






            share|improve this answer




















            • didn't work, now show empty entries
              – Luis González
              Nov 11 at 3:44















            up vote
            0
            down vote













            For this loop you can use:



            $scope.data = ;
            angular.forEach(json, (item) =>
            // here you can get item.age and item.name
            $scope.data.push(item);
            );


            At the end of this loop your $scope.data will have all students in it






            share|improve this answer




















            • didn't work, now show empty entries
              – Luis González
              Nov 11 at 3:44













            up vote
            0
            down vote










            up vote
            0
            down vote









            For this loop you can use:



            $scope.data = ;
            angular.forEach(json, (item) =>
            // here you can get item.age and item.name
            $scope.data.push(item);
            );


            At the end of this loop your $scope.data will have all students in it






            share|improve this answer












            For this loop you can use:



            $scope.data = ;
            angular.forEach(json, (item) =>
            // here you can get item.age and item.name
            $scope.data.push(item);
            );


            At the end of this loop your $scope.data will have all students in it







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 at 2:02









            el Corleone

            11




            11











            • didn't work, now show empty entries
              – Luis González
              Nov 11 at 3:44

















            • didn't work, now show empty entries
              – Luis González
              Nov 11 at 3:44
















            didn't work, now show empty entries
            – Luis González
            Nov 11 at 3:44





            didn't work, now show empty entries
            – Luis González
            Nov 11 at 3:44













            up vote
            0
            down vote













            In my opinion your JSON is valid, try to change format of JSON for something similar to this :



             $scope.data = [
            "name": "json[0].name",
            "age": "json[0].age"
            ,

            "name": "json[1].name",
            "age": "json[1].age"

            ]


            Then you can easly console or show it



            angular.forEach($scope.data, function (value, index) 
            console.log($scope.data[index] + ' ' + index);
            );


            HTML



            <ul ng-repeat="json in data">
            <li><b>Name: </b> <p>json.name</p> <b>Age: </b> <p>json.age</p></li>
            </ul>


            plunker: http://plnkr.co/edit/s6ix8aEDz0jR3UeXGL6M?p=preview






            share|improve this answer
























              up vote
              0
              down vote













              In my opinion your JSON is valid, try to change format of JSON for something similar to this :



               $scope.data = [
              "name": "json[0].name",
              "age": "json[0].age"
              ,

              "name": "json[1].name",
              "age": "json[1].age"

              ]


              Then you can easly console or show it



              angular.forEach($scope.data, function (value, index) 
              console.log($scope.data[index] + ' ' + index);
              );


              HTML



              <ul ng-repeat="json in data">
              <li><b>Name: </b> <p>json.name</p> <b>Age: </b> <p>json.age</p></li>
              </ul>


              plunker: http://plnkr.co/edit/s6ix8aEDz0jR3UeXGL6M?p=preview






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                In my opinion your JSON is valid, try to change format of JSON for something similar to this :



                 $scope.data = [
                "name": "json[0].name",
                "age": "json[0].age"
                ,

                "name": "json[1].name",
                "age": "json[1].age"

                ]


                Then you can easly console or show it



                angular.forEach($scope.data, function (value, index) 
                console.log($scope.data[index] + ' ' + index);
                );


                HTML



                <ul ng-repeat="json in data">
                <li><b>Name: </b> <p>json.name</p> <b>Age: </b> <p>json.age</p></li>
                </ul>


                plunker: http://plnkr.co/edit/s6ix8aEDz0jR3UeXGL6M?p=preview






                share|improve this answer












                In my opinion your JSON is valid, try to change format of JSON for something similar to this :



                 $scope.data = [
                "name": "json[0].name",
                "age": "json[0].age"
                ,

                "name": "json[1].name",
                "age": "json[1].age"

                ]


                Then you can easly console or show it



                angular.forEach($scope.data, function (value, index) 
                console.log($scope.data[index] + ' ' + index);
                );


                HTML



                <ul ng-repeat="json in data">
                <li><b>Name: </b> <p>json.name</p> <b>Age: </b> <p>json.age</p></li>
                </ul>


                plunker: http://plnkr.co/edit/s6ix8aEDz0jR3UeXGL6M?p=preview







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 8:39









                BartoszTermena

                3366




                3366



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245090%2fangularjs-and-jquery-datatable-with-ui-bootstrap-need-to-show-entries-in-json%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    ReactJS Fetched API data displays live - need Data displayed static

                    政党