2013-07-08 38 views
1

我是jQuery jTable插件的新手。考慮this snippet from an official sample在jtable中訪問JSON

Phones: { 
title: '', 
width: '5%', 
sorting: false, 
edit: false, 
create: false, 
display: function (studentData) { 
... 
... 
title: studentData.record.Name + ' - Phone numbers', 

actions: { 
listAction: '/Demo/PhoneList?StudentId=' + studentData.record.StudentId, 

爲什麼是它在訪問JSON,record是小寫 -

.... 
    return Json(new { Result = "OK", Records = students, TotalRecordCount = studentCount }); 
.... 
-

studentData.record.StudentId 

,而這是從ASP.NET MVC控制器代碼發送

和發送的JSON看起來像這樣 -

{"Result" : "OK", Records : [{"StudentId":1 .... }], TotalRecordCount=5 } 

我的問題是如何在示例工作代碼時StudentId作爲

studentData.record.StudentId 

訪問,而訪問JSON數據的常規方式是這樣的基礎上,JSON以上,實際上是發出 -

studentData.Record.StudentId 

爲什麼當我嘗試訪問studentData.Record.TotalRecordCountstudentData.record.TotalRecordCount時返回undefined

如何在JavaScript中訪問TotalRecordCount的值?我可以添加自定義JSON變量(除Result,Records,TotalRecordCount)&訪問它們的值嗎?

+0

您並未發佈所有代碼,我可以猜測studentData是學生枚舉上的迭代器。請發佈完整的代碼示例。 – Maess

+0

完整的示例在這裏 - http://www.jtable.org/demo/masterchild – user2011507

回答

2

我正在尋找相同的東西,以加載數據時將計數放在標籤中。 跨越這個剛剛來到: https://github.com/hikalkan/jtable/issues/169 關於一半,我發現他們引用「data.serverResponse」

我想這工作的下面的代碼:

"recordsLoaded": function (event,data) { 
    $('#tab').html("Items ("+data.serverResponse.TotalRecordCount+")"); 
} 

所以,貌似可以訪問原始JSON通過data.serverResponse。