这与称为 ProcessMaker 的 BPM 应用程序有关,但逻辑和语法应该相对相同。我正在尝试从另一个已将数据传递到隐藏字段的序列化网格填充一个网格(基本上是一个表)。
传递给隐藏字段的数据格式如下:
前任:
{"1":{"id":"4332","product":"ball","price":"$5.00",”ordered":"On"}
下面在 processmaker 的 wiki 上找到的 javascript 示例将隐藏字段反序列化为一个对象,并使用其信息填充一个新网格,无论它是什么。processmaker 的 wiki 上的示例使用 eval 函数,但您将如何使用 json.parse() 函数对其进行转换?
function populateGrid() {
var grd = getObject("newAccountsGrid");
//remove all existing rows in the grid (except the first one):
var i = Number_Rows_Grid("newAccountsGrid", "accId");
for (; i > 1; i--)
grd.deleteGridRow(i, true);
//The first row can't be deleted, so clear the fields in the first row:
for (i = 0; i < grd.aFields.length; i++)
getGridField("contactsGrid", 1, grd.aFields[i].sFieldName).value = "";
//unserialize the hidden field as an object:
var oAccounts = eval('(' + getField("sAccounts").value + ')');
if (typeof oAccounts == 'object') {
for (var rowNo in oAccounts) {
if (rowNo != 1)
grd.addGridRow();
getGridField('newAccountsGrid', rowNo, 'accId').href = oAccounts[rowNo]["accountId"];
getGridField('newAccountsGrid', rowNo, 'accName').href = oAccounts[rowNo]["accountName"];
getGridField('newAccountsGrid', rowNo, 'createDate').href = oAccounts[rowNo]["created"];
}
}
}
populateGrid(); //execute when the DynaForm loads