我正在尝试向我的数据源添加一个项目,然后根据这个答案重新加载网格。网格加载正常。被addItemToGrid
调用了几次,我正在验证基础 tableSrc 对象是否被添加,但网格保持不变。
var tableSrc = { "rows": [
{ "title": "Title1", "subtitle": "subTitle", "authors": ["a1", "a2", "a3"] },
{ "title": "Title2", "subtitle": "subtitle", "authors": ["X", "Y"] },
{ "title": "Title3", "subtitle": "subTitle", "authors": ["1", "2", "3", "4"]}]
};
targetGrid = $("#jqGridElement").jqGrid({
datastr: tableSrc,
jsonReader: { repeatitems: false },
datatype: "jsonstring",
colNames: ['title', 'subtitle'],
colModel: [
{ name: 'title', index: 'title', width: 55 },
{ name: 'subtitle', index: 'subtitle'}],
height: 'auto',
gridview: true
});
function addItemToGrid() {
tableSrc.rows.push({ "title": "NEW", "subtitle": "HELLO", "authors": ["1", "2", "3", "4"] });
$("#jqGridElement").trigger('reloadGrid');
//$("#jqGridElement").jqGrid('reloadGrid');
}