gpt4 book ai didi

java - Smart gwt如何根据数据将图像添加到网格单元

转载 作者:行者123 更新时间:2023-12-02 04:38:24 28 4
gpt4 key购买 nike

“计数”列接收的数据是一个 int (0, 1, 2, ...)。对于 0 的单元格不应显示任何内容,当数据 > 0 时,应显示图像。

  count.setImageURLPrefix("silk/");
count.setImageURLSuffix(".png");

这样我应该添加具有不同名称的相同图像(2.png,1.png等)

如何做到这一点?

最佳答案

如果你已经收到了count的值,那么在将数据加载到grid中时,可以直接使用setAttribute方法并提供要使用的图像。

您需要定义一个隐藏字段来存储计数的 int 值,以及定义一个图像字段来在 UI 上显示图像。

这里,计数图像将是添加到 ListGrid 的 listGridField,可以定义为:

private ListGridField count = new ListGridField("count", "Count");
count.setType(ListGridFieldType.IMAGE);
count.setAlign(Alignment.CENTER);
count.setDefaultValue("blank.png");
count.setCanEdit(false);

加载数据时,其值可以设置为:

ListGridRecord recordTemp = new ListGridRecord();
//add logic to check count int value and set the value accordingly below
recordTemp.setAttribute("count","1.png");
//set other existing attributes
//...
dataSource.getInstance().addData(recordTemp);

另外,如果count的值是动态更新的,那么可以添加changeHandler()来相应地设置属性值。

关于java - Smart gwt如何根据数据将图像添加到网格单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30473208/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com