如何在ScriptProperties中存储和检索数组?

cra*_*ice 2 javascript google-apps-script

在处理程序函数内部我正试图存储并获取名为"theses"的数组数组的值:

 var fact_list = [ ["Kennedy Inauguration", "politics", "tZwnNdFNkNklYc3pVUzZINUV4eUtWVWFSVEf"], ["Pericles’ Funeral Oration", "politics", "sdgrewaNkNklYc3pVUzZINUV4eUtW345ufaZ"], ["The Pleasure of Books", "culture", "1234rFszdgrfYc3pVUzZINUV4eU43usacd"], ["I Am The First Accused (Nelson Mandela)", "law", "34rsgadOsidjSZIswjadi95uydnfklsdks"] ];
function submit(e){
  Logger.log("running submit(e)"); 
  var numberOfItems = e.parameter.checkbox_total;
  var itemsSelected = [];
  // for each item, if it is checked / selected, add it to itemsSelected
  for(var i = 0; i < numberOfItems; i++){
    if(e.parameter['checkbox_isChecked_'+i] == 'true'){
      itemsSelected.push(e.parameter['checkbox_value_'+i]);
    }
  }
  var app = UiApp.getActiveApplication();

  Logger.log("itemsSelected = " + itemsSelected);

  ScriptProperties.setProperties({'theses': itemsSelected}, true); 


  var thesesArrays = ScriptProperties.getProperty('theses');
  Logger.log("thesesArrays = " + thesesArrays);
  for (var i = 0; i < thesesArrays.lenght(); i++){
       var thesesId = ScriptProperties.getProperty('theses')[i][2];
       var thesesType = ScriptProperties.getProperty('theses')[i][1];
       importTheses(target, thesesId, thesesType);
}       
  app.close();
  return app;
}
Run Code Online (Sandbox Code Playgroud)

但是当代码得到行时for (var i = 0; i < thesesArrays.lenght(); i++){我得到了一个错误,因为thesesArrays它不是一个数组数组(正如我的意图),而是一个没有该lenght()方法的对象.

我该如何解决这个问题?如何在ScriptProperties中存储和检索数组?

Zig*_*del 12

另一个答案仅涉及长度上的语法错误.但它仍然无法工作,因为您只能在scriptProperties中存储字符串.

1)json.stringify您的数组将其存储为字符串

2)不要将getProperty调用一百万次.在循环之前调用它一次并将json.parse调入数组.