這屬於稱爲ProcessMaker的BPM應用程序,但邏輯和語法應相對相同。我試圖從 填充一個網格(基本上是一張表格),從另一個序列化網格中將數據傳遞到隱藏字段。將eval解析轉換爲json.parse
傳遞到隱藏字段中的數據的格式如下:
例:
{"1":{"id":"4332","product":"ball","price":"$5.00",」ordered":"On"}
下面的JavaScript示例上processmaker的wiki發現unserializes隱藏字段作爲一個對象,並使用它的信息填充一個新的網格,無論它是什麼。 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
你有沒有試過閱讀'JSON.parse()'? https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse – zerkms