2016-04-20 35 views
0

我將最後一行從JSON在JavaScript中創建一個DataGrid(代碼複製here) 我是能夠生產這種jeasyui數據網格的InsertRow

{amountA:'99,865.65', amountB:'47,781.91', amountTotal:'147,647.56'} 

要插入,

function insertRow(index, thisRow) { 
$("#tDataGrid").datagrid('insertRow', { 
    index: index, 
    row: thisRow 
}); 

這是不行的,但是當我複製了產生JSON的代碼一樣

 index: index, 
    row: {amountA:'99,865.65', amountB:'47,781.91', amountTotal:'147,647.56'} 

它完美運作。

我的代碼有什麼問題? 在此先感謝。

+0

仍有問題。不知道該怎麼做。這似乎很簡單,但有時候,簡單的事情是最複雜和難以解決的。 :'( – amrodelas

+0

)如果你仍然有問題,請發佈一個簡單的例子,顯示一個調用insertRow不起作用的例子。 –

回答

0

嘗試這種方式一般

$('#tDataGrid').datagrid({ 
data: [ 
    {amountA:'value11', amountB:'value12', amountC:'value12'}, 
    {amountA:'value11', amountB:'value12', amountC:'value12'} 
] 
}); 

添加附加一個新行。新行會加入到最後的位置:

$('#tDataGrid').datagrid('appendRow',{ 
amountA: 123, 
amountB: 123, 
amountC: 'some Text' 
}); 

插入在第二排位置的新行。

$('#tDataGrid').datagrid('insertRow',{ 
index: 1, // index start with 0 
row: { 
    amountA: 123, 
    amountB: 123, 
    amountC: 'some Text' 
} 
}); 
+0

這是OP正在做的事情,不是嗎? –

+0

它幾乎是同樣,他可以在不使用Row Object的情況下嘗試Data對象,如果他將很多JSON行發送到'thisRow',那麼這將是一個問題 –