I am using an Angular DataTable to display data using a JSON array but the data did not display. I think there is an issue with my HTML page. Can you find the issue?
HTML file:
<tbody>
<tr ng-repeat="user in userList">
<td><a class="green shortinfo" href="javascript:;" ng-click="childInfo(user, $event)" title="Click to view more"><i class="glyphicon glyphicon-plus-sign"></a></td>
<td>{{user.name}}</td>
<td>{{user.position}}</td>
<td>{{user.office}}</td>
<td><div class="btn-group">
<button type="button" class="btn btn-default btn" ng-click="edit($index);"><i class="glyphicon glyphicon-pencil"></i></button>
<button type="button" class="btn btn-default btn" ng-click="delete();"><i class="glyphicon glyphicon-trash"></i></button>
</div></td>
</tr>
</tbody>
This is part of the HTML page:
MY JSON data format:
$scope.userList = {"InvoiceHeaders":[
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "320,800ドル",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"name": "Garrett Winters",
"position": "Accountant",
"salary": "170,750ドル",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
}
]; }
James Martinez
1892 silver badges11 bronze badges
asked Oct 27, 2018 at 4:05
kumara
9374 gold badges23 silver badges47 bronze badges
-
Would your problem be that userList is not actually a list or users, but rather a JS object with a single property named InvoiceHeaders whose value is a list of users?moilejter– moilejter2018年10月27日 04:13:10 +00:00Commented Oct 27, 2018 at 4:13
-
i am trying to use datatable example to my project.kumara– kumara2018年10月27日 04:14:25 +00:00Commented Oct 27, 2018 at 4:14
-
Try setting $scope.userList = [ { "name" : "Tiger", ... }, { "name" : "Garret", .. } ]; ...moilejter– moilejter2018年10月27日 04:18:44 +00:00Commented Oct 27, 2018 at 4:18
-
copy and paste your JSON code to jsonlint.com, you should remove the trailing ; after ]James Martinez– James Martinez2018年10月27日 04:21:16 +00:00Commented Oct 27, 2018 at 4:21
1 Answer 1
Your JSON is not valid , change it as,
{
"InvoiceHeaders": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "320,800ドル",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"name": "Garrett Winters",
"position": "Accountant",
"salary": "170,750ドル",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
}
]
}
DEMO
var myApp = angular.module('testApp',[]);
myApp.controller('myCtrl',function($scope){
$scope.userList = {
"InvoiceHeaders": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "320,800ドル",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
{
"name": "Garrett Winters",
"position": "Accountant",
"salary": "170,750ドル",
"start_date": "2011/07/25",
"office": "Tokyo",
"extn": "8422"
}
]
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="myCtrl">
<ul ng-repeat="user in userList.InvoiceHeaders">
<li>{{user.name}}</li>
<li>{{user.position}}</li>
<li>{{user.office}}</li>
<td>
</ul>
</body>
answered Oct 27, 2018 at 5:21
Sajeetharan
223k65 gold badges370 silver badges409 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-js