我是位jquery的新手,並試圖提高技能。 我已經從ajax調用了json字符串。現在我只需要根據網格大小來劃分它;如何打破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}]
,我做Json.Parse(data.d)
阿賈克斯成功後,所以它轉換成對象;
如何是你的JSON格式?你能告訴我們一個關於你的數據應該如何存儲到數組中的例子嗎?任何jsfiddle? – Andres 2014-10-30 15:16:18
@Andres我編輯過,請檢查 – 2014-10-30 15:22:38
當你說_pageSize = 10時,你的意思是什麼?你想打印10個頁面元素? – Andres 2014-10-30 15:26:43