我在我的AJS应用程序中使用JQuery Datatables来加载从$ http GET请求中检索的数据。我已经尝试搜索有关如何加载通过我的AJS应用程序检索的数据的任何示例 - 服务> $ http GET调用datatable但找不到任何。那么有谁知道我怎么做到这一点?任何信息,示例或问题相关资源都非常感谢。感谢
注意:从$ http GET调用中检索的数据采用以下格式:
[{"_id":"543e58b862744980197026a8","title":"Mr.","firstName":"Michael","lastName":"A","email":"michael@gmail.com","address":"New York","password":"123456","activeMember":true,"__v":0,"role":"Member","memberSince":"2014-10-15T11:21:28.884Z"},{"_id":"543e591862744980197026a9","title":"Ms","firstName":"Mary","lastName":"W","email":"mary@gmail.com","address":"New York","password":"123456","activeMember":true,"__v":0,"role":"Admin","memberSince":"2014-10-15T11:23:04.382Z"}]
答案 0 :(得分:0)
我假设您使用的数据表是:http://www.datatables.net/。在这种情况下,我建议您使用angular从服务器获取数据并构建表。之后将html表id传递给jquery datatable。
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {
// load data from array as example
$scope.items = [{
firstName: 'foo',
lastName: 'bar'
}, {
firstName: 'buzz',
lastName: 'booo'
}, {
firstName: 'zxzz',
lastName: 'yyy'
},
];
}]);
//Use this to get data from server
/*
$http.get('url').success(function (data, status, headers, config) {
$scope.items = data;
}).
error(function (data, status, headers, config) {
});
*/
// pass to jquery data table
$(document).ready(function () {
$('#example').DataTable();
});