找回密码
 立即注册

QQ登录

只需一步,快速开始

右手微笑
金牌服务用户   /  发表于:2023-8-1 15:50  /   查看:1134  /  回复:5
1金币
想要获取到comboBox选中项的索引,而不是value,因为value有可能存在多个选项value一样的情况,请问有相关方法吗

最佳答案

查看完整内容

editorValueType的设置应该是一次性的,目前不支持更改,这是目前产品的设计。 如果想要直接获取到index,那么在一开始设置单元格类型的时候就应该将该Combobox的editorValueType的值设置为1。

5 个回复

倒序浏览
最佳答案
最佳答案
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2023-8-1 15:50:07
来自 6#
右手微笑 发表于 2023-8-2 11:25
测试了一下,设置完cellType.editorValueType(1)之后,必须要重新点击下拉列表选择一次选项,有这个动作之 ...

editorValueType的设置应该是一次性的,目前不支持更改,这是目前产品的设计。

如果想要直接获取到index,那么在一开始设置单元格类型的时候就应该将该Combobox的editorValueType的值设置为1。
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2023-8-1 16:47:11
2#
您好,将EditorValueType设置为index即可:

image.png634309081.png
回复 使用道具 举报
右手微笑
金牌服务用户   /  发表于:2023-8-1 17:54:29
3#
Joestar.Xu 发表于 2023-8-1 16:47
您好,将EditorValueType设置为index即可:

我的代码如下,取出来的value不是index,能否给一个demo看一下:
const celltype = this.sheet.getCellType(startSelection[0].row, startSelection[0].col);
if (celltype instanceof window.GC.Spread.Sheets.CellTypes.ComboBox) {
  this.comboBoxList = celltype.items();
  celltype.editorValueType(1);
  this.sheet.repaint()
  const value = this.sheet.getValue(startSelection[0].row, startSelection[0].col)
}
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2023-8-2 09:02:49
4#
通过以下代码即可取出index:

let designer = GC.Spread.Sheets.Designer.findControl(document.querySelector(".gc-designer-container"));
let spread = designer.getWorkbook();
let sheet = spread.getActiveSheet();

var cellType2 = new GC.Spread.Sheets.CellTypes.ComboBox();
cellType2.items(["a","b","c"]);
sheet.getCell(2, 2).cellType(cellType2);
console.log(cellType2.editorValueType());

cellType2.editorValueType(1);

sheet.getValue(2,2);

image.png454817199.png
回复 使用道具 举报
右手微笑
金牌服务用户   /  发表于:2023-8-2 11:25:02
5#
测试了一下,设置完cellType.editorValueType(1)之后,必须要重新点击下拉列表选择一次选项,有这个动作之后,在通过getValue取出来的才是index,如果设置完cellType.editorValueType(1)之后,立即getValue,取出来的还是text。
我想直接去取当前选中项的index,不要做任何手动操作,有什么方法可以实现呢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部