2012-09-27 24 views
0

我在調用ajaxcontroller從服務器獲取數據。 ajaxController.fetchCounts(callFetchcounts);在dwr中處理java List addRows函數

callFetchcounts,這個函數會在我得到數據後調用。 我處理這樣的:

var callFetchcounts = function(data) { 
if(data.length > 0){ 
    dwr.util.addRows("rounded-corner",[data] , cellFuncs, { escapeHtml:false }); 
}} 

var cellFuncs = [ 
function(data) {return data.category}, 
function(data) {return data.count}, 
function(data) {return "<a href=''>Edit</a>"} 
]; 

從ajaxController我將獲得對象的列表。 (我甚至可以獲取對象數組)。 我想填充一個表格,其中行數=結果列表/數組中的元素數目。列數=每個列表對象中的元素數量。 我想用List對象的數據填充列。

如何做到這一點?我感到震驚。 任何人都可以幫助我一個例子。

感謝, Tiru

回答

0

你幾乎完成你的使命!
所有你需要做的是在你的代碼調整幾個點,檢查出來:

function fillTable(data) { 
 
\t \t if(data.length > 0){ 
 
\t \t \t var cellFuncs = [ 
 
\t \t \t function(data) {return data.category}, 
 
\t \t \t function(data) {return data.count}, 
 
\t \t \t function(data) {return "<a href='#'>Edit</a>"} 
 
\t \t \t ]; 
 
\t \t \t 
 
\t \t \t // You don't have to use [data] if data is a list(array) of objects 
 
\t \t \t // User [data] only if data is a single object 
 
\t \t \t dwr.util.addRows("rounded-corner", data , cellFuncs, { escapeHtml:false }); 
 
\t \t } 
 
}