如何根据页面大小断开json字符串
How To break json string According To Page size?
我是jquery的新手,正在努力提高技能。我从ajax调用中得到了json字符串。现在我只需要根据网格页面大小进行划分;
我的逻辑是这样的。
首先,我已经采取了字符串内对象的长度
var _totalLength = returnedData.length;
var _pageSize = 10;
var _totalPageRequired = Math.ceil(returnedData.length / _pageSize);
var array = new Array(_totalPageRequired);
现在我只需要创建一个数组,并根据里面的页面大小放置记录
var array = new Array(_totalPageRequired);
现在我运行for
循环直到_totalPageRequired
for (var i = 0; i < _totalPageRequired; i++) {
//here i am stucked, i want to know how could i assign
//per array[i] = the required data from the json string
// _totalLength = 43 and _pageSize = 10 therefore totalpagedata required is 5
// for ex: array[0] = returnedData[from index 0 to 9]
// array[1] = returnedData[from index 10 to 19] and so on
// array[4] = returnedData[from index 40 - 43] as records end
}
任何人都可以帮我破解这个json字符串。
编辑:我的Json字符串类似
[{"UserRates":null,"RoleId":2,"Name":"M.Hassaan Khan","RoleName":null,"Password":null,"EmployeeRate":null,"Gender":null,"CategoryId":0,"CategoryName":null,"ClientId":0,"ClientName":null,"UserId":2,"Username":"hassaan09","IsMapped":false,"ProjectId":0,"ProjectName":null,"ProjectTitle":null,"CreationDate":"0001-01-01T00:00:00","ExpectedEndingdate":"0001-01-01T00:00:00","Description":null,"ParentProjectId":0,"Cost":0.0,"Status":false},{"UserRates":null,"RoleId":2,"Name":"Bilawaal","RoleName":null,"Password":null,"EmployeeRate":null,"Gender":null,"CategoryId":0,"CategoryName":null,"ClientId":0,"ClientName":null,"UserId":5,"Username":"test_09","IsMapped":false,"ProjectId":0,"ProjectName":null,"ProjectTitle":null,"CreationDate":"0001-01-01T00:00:00","ExpectedEndingdate":"0001-01-01T00:00:00","Description":null,"ParentProjectId":0,"Cost":0.0,"Status":false},{"UserRates":null,"RoleId":2,"Name":"Zardari","RoleName":null,"Password":null,"EmployeeRate":null,"Gender":null,"CategoryId":0,"CategoryName":null,"ClientId":0,"ClientName":null,"UserId":18,"Username":"register_09","IsMapped":false,"ProjectId":0,"ProjectName":null,"ProjectTitle":null,"CreationDate":"0001-01-01T00:00:00","ExpectedEndingdate":"0001-01-01T00:00:00","Description":null,"ParentProjectId":0,"Cost":0.0,"Status":false},{"UserRates":null,"RoleId":2,"Name":"Nawaz","RoleName":null,"Password":null,"EmployeeRate":null,"Gender":null,"CategoryId":0,"CategoryName":null,"ClientId":0,"ClientName":null,"UserId":30,"Username":"testing111","IsMapped":false,"ProjectId":0,"ProjectName":null,"ProjectTitle":null,"CreationDate":"0001-01-01T00:00:00","ExpectedEndingdate":"0001-01-01T00:00:00","Description":null,"ParentProjectId":0,"Cost":0.0,"Status":false}]
在ajax成功之后,我正在做Json.Parse(data.d)
,所以它将它转换为对象;
试试这个:http://jsfiddle.net/aras7/b83uzccn/1/
var _totalLength = returnedData.length;
var _pageSize = 2;
var array = [];
var page = 0;
for(var i = 0;i < returnedData.length;){
var page_data = [];
for(var j = 0;j < _pageSize && i < returnedData.length;j++) {
page_data.push(returnedData[i]);
i++;
}
array.push(page_data)
}
在我的手机上输入这个,这样它就没有解释了,希望它能有所帮助,这就是你想要的。
var _totalLength = returnedData.length;
var _pageSize = 10;
var array = [];
var i = -1;
var currenPage:
while(++i< _totalLength){
currentPage = Math.floor(i/_pageSize);
array [currentPage] = array [currentPage] || [];
array [currentPage].push(returnedData[i]);
}
相关文章:
- jQuery匹配JSON对象的部分文本
- 在循环中分配json值时,值被覆盖
- 需要帮助设置json数组
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 使用JQuery解析JSON嵌套数组
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 如何使用json将对象列表从java转换为javascript
- 如何使用 node.js 比较两个 json 数组
- 如何将JSON数据导入我的ejs模板
- 区分JSON中的矩阵和列表列表
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- PHP-JSON :检查断开的链接
- 如何根据页面大小断开json字符串
- 断开JSON对象
- 断开JSON对象并添加到表中
- 在angularjs中的特定位置删除并断开json中的数据