2013-10-25 53 views
0

如何使用具有特定列的JSON對象使用Jquery構建數據表。 在服務器端我的示例JSON對象,我所要建造,如何使用帶有JSON對象的Jquery構建數據表

Response":{"employeesArray": 
      [{"empName":"sarvesh","empId":121,"dept":"Java","salary":"200","exp":2,}, 
      {"empName":"satish","empId":122,"dept":".net","salary":"200","exp":3} 
      ]} 

現在我想打造專業化使用jQuery與像EMP ID,EMP名,EXP,部門具體列的數據表。我怎樣才能做到這一點?有一些這樣的事情。但我不知道如何建立?普雷斯幫助我。

$('#example').dataTable({ 
}); 

回答

0
function fillTable(employeesArray){ 
    $('#table').html(''); 
    $('#table').append(<tr><th>Employee Name</th><th>Employee iD</th><th>Department</th><th>Salary</th><th>Experience</th></tr>); 
    for(i in employeesArray){ 
     $('#table').append(<tr><td>employeesArray[i].empName</td><td>employeesArray[i].empId</td><td>employeesArray[i].dept</td><td>employeesArray[i].salary</td><td>employeesArray[i].exp</td></tr>); 
    } 
} 
+0

Bhuwan感謝您的答覆。但在這裏你的建築表迭代。我期待像下面這樣。爲什麼因爲我不得不在數據表$(document).ready(function(){var 0Table = $('#jQueryDataTable')上操作很多。的dataTable({ \t 「bProcessing」:真的, \t 「sAjaxSource」: 「/getEmployeesAction.do」, \t 「aoColumns」:[ \t { 「employeesArray」: 「empName」}, \t { 「employeesArray」: 「EMPID」}, \t { 「employeesArray」: 「工資」}, \t] \t}); \t}) –

+0

當我試圖這樣做時,它會發出警告,如「DataTables警告:試圖在不是表格的節點上初始化DataTable:DIV」。 –

+0

您是否嘗試過在Google上搜索錯誤消息? – writeToBhuwan

相關問題