【发布时间】:2017-02-28 21:22:57
【问题描述】:
我已经研究了一段时间,但还没有找到合适的答案(大多数涉及切换到 setChoiceValues(),而不是使用 setChoices([]) 解决“无法将数组转换为 Choice[]”问题) .
在尝试通过 Google 脚本生成表单部分和问题时,我遇到了一个问题,即我的答案选择无法根据用户的答案转到特定页面。这似乎是 setChoiceValues() 和 setChoices([]) 之间的区别,后者尽可能地允许页面导航。
但是,当尝试将我的新选项数组放入 setChoices([]) 时,我收到错误消息“无法将数组转换为选项 []”。否则我的代码工作正常,但我需要使用 setChoices([]) (似乎)以获得我想要的页面导航。
如何将值循环到数组或其他容器中,并使它们显示为 Choices[] 对象?我怎样才能使这样的工作?看起来它应该比现在容易得多,但我看不到解决方案。
下面是导致问题的一段代码:
//Form - globally accessible
var f = FormApp.openById(f_id);
//Date Iterator
var curr_date = 0;
//Time Iterator
var curr_time = 0;
//Array of Times
var Tchoices = [];
//Setting Time choices per date
while(curr_date < dates.length)
{
Tchoices = [];
curr_time = 0;
//dates is an array of objects with both d's (single date) and t's
// (array of times for that date)
var d = dates[curr_date].d;
var end_break = f.addPageBreakItem().setTitle("Times for " + d);
var f_time = f.addMultipleChoiceItem().setTitle(d);
while(curr_time < dates[curr_date].t.length)
{
end_break = end_break.setGoToPage(FormApp.PageNavigationType.SUBMIT);
Tchoices.push(f_time.createChoice(dates[curr_date].t[curr_time], end_break).getValue());
curr_time++;
}
f_time.setChoices([Tchoices]);
}
【问题讨论】:
标签: javascript arrays google-apps-script google-forms