我有一个JSON,我从服务中获得我想使用json存储在我的字符串变量中。 所以我的分页工作。
var app = angular.module('Techapp', ['ngTable']);
app.controller('ngTableCtrl', function ($scope, ngTableParams) {
var data = [{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Material", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Shanthi_A" },
{ Technology: "Core JAVA", CourseType: "Training Material", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Material", JobLevelPrefered: "JL 3+", ContactPerson: "Muthumari_T" },
{ Technology: "Core JAVA", CourseType: "Checklists", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Material", JobLevelPrefered: "JL 3+", ContactPerson: "Vatsala_Agrawal" },
{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Material", JobLevelPrefered: "JL 3+", ContactPerson: "Selvam_K01" },
{ Technology: "Core JAVA", CourseType: "Checklists", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" },
{ Technology: "Core JAVA", CourseType: "Training Plan", JobLevelPrefered: "JL 3+", ContactPerson: "Kavitha_arjun" }
];
$scope.tableParams = new ngTableParams(
{
page: 1, // show first page
count: 5 // count per page
},
{
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
app.controller('CertificationCtrl', function ($scope, ngTableParams, $http) {
var url = "http://localhost:58402/Search.svc/abc/ListsJava/Certification";
$http.get(url)
.success(function (data) {
var myjson = JSON.parse(data);
$scope.Title = JSON.parse(myjson)
});
var data = [];
$scope.tableParams = new ngTableParams(
{
page: 1, // show first page
count: 5 // count per page
},
{
total: data.length, // length of data
getData: function ($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
由于
喜欢
答案 0 :(得分:0)
如果http://localhost:58402/Search.svc/abc/ListsJava/Certification
已经返回您的JSON数据,那么您不能只在success
回调中调用您的分页代码,如下所示:
app.controller('CertificationCtrl', function ($scope, ngTableParams, $http) {
var url = "http://localhost:58402/Search.svc/abc/ListsJava/Certification";
$http.get(url)
.success(function (data) {
$scope.tableParams = new ngTableParams(
{
page: 1, // show first page
count: 5 // count per page
},
{
total: data.length, // length of data
getData: function ($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
});
<强>更新强>
请参阅jsfiddle上的现场演示。不要担心Javascript部分中的第1行到第10行;我用它来设置要发送到jsfiddle echo服务的测试数据。将第11行的url
变量替换为您的网址。
另请注意,我正在使用$http.post
进行演示,并且还删除了所有JSON.parse()
代码。