我想获取 Google Apps 脚本列表框中所选项目的索引,而不是所选项目本身。到目前为止我看到的所有示例都创建了一个服务器处理程序,通过以下方式获取列表框的值
var list1Value = e.parameter.list1;
我想获取索引,这样我就可以索引到数组中。我尝试使用这个解决方案http://productforums.google.com/forum/#!category-topic/apps-script/services/vXa57-9T6E4 http://productforums.google.com/forum/#!category-topic/apps-script/services/vXa57-9T6E4但我的脚本抱怨 indexOf 未被识别
var currentmonth = months.indexOf(e.parameter.list1);
有人对如何获取索引有好主意吗?顺便说一句,这是一个在站点中运行的谷歌应用程序脚本,而不是在电子表格中运行,如果这有什么不同的话。
另一个答案没有多大意义,因为 Google Apps 脚本是在 Google 的服务器上执行的,而不是在您的浏览器中执行的indexOf()
在GAS中得到了广泛认可。
您应该使用包含 listBox 元素的数组,然后使用listArray.indexOf(listelement);
您将获得所选项目的索引。
例子 :
//in the UI construction
var ItemlistArray = ['item1','item2','item3','item4'];// note that this variable definition could be placed outside of the function so it becomes a global variable...
for (n=0,n<ItemlistArray.length;++n){
ListBox.addItem(ItemlistArray[n]
}
//in the Handler function
var item = e.parameter.listBoxName
var ItemlistArray = ['item1','item2','item3','item4'];// if ItemlistArray is global this line can be removed
var index = ItemlistArray.indexOf(item); // if for example the selected item was 'item3', index will be 2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)