2016-04-20 29 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',那么这将是一个问题 –