2012-12-28 2 views
-1

이것은 ProcessMaker라고하는 BPM 응용 프로그램과 관련이 있지만 논리와 구문이 비교적 같아야합니다. 나는 데이터를 숨겨진 필드에 전달 된 다른 직렬화 된 표에서 표 (기본적으로 테이블) 채 웁니다.eval 구문을 json.parse로 변환

예 : 다음과 같이 숨겨진 필드에 전달

데이터 포맷

{"1":{"id":"4332","product":"ball","price":"$5.00",”ordered":"On"} 

processmaker의 위키에서 발견 아래 자바 스크립트 예제는 객체로 숨겨진 필드를 unserializes 및 채우기 위해 그 정보를 사용하여 새로운 그리드가 무엇이든간에 명명되었습니다. processmaker의 위키에있는 예제는 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 
+1

'JSON.parse()'에 대해 읽으려고 했습니까? https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse – zerkms

답변

1

처럼 간단 할 것이다 :

var oAccounts = JSON.parse(getField("sAccounts").value); 
0

eval("("+something+")")JSON.parse(something)

0

(ProcessMaker 위키)이 예를 들어 위의 몇 줄이 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 = JSON.parse(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 
관련 문제