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>
javascript angularjs json for-loop
add a comment |
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>
javascript angularjs json for-loop
add a comment |
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>
javascript angularjs json for-loop
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
javascript angularjs json for-loop
edited Nov 11 at 3:47
dmcgrandle
826215
826215
asked Nov 11 at 1:33
Luis González
83
83
add a comment |
add a comment |
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
didn't work, now show empty entries
– Luis González
Nov 11 at 3:44
add a comment |
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
add a comment |
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
didn't work, now show empty entries
– Luis González
Nov 11 at 3:44
add a comment |
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
didn't work, now show empty entries
– Luis González
Nov 11 at 3:44
add a comment |
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
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
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 11 at 8:39
BartoszTermena
3366
3366
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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