【发布时间】:2014-03-26 20:46:32
【问题描述】:
我有一个 GXT 3 应用程序,我正在尝试使用 ToggleButtonCell 来允许用户修改布尔值。
这是数据的代码:
public class InspectionListGridData {
private Boolean posted;
public InspectionListGridData(InspectionListGridData dataToCopy) {
setPosted(dataToCopy.getPosted());
}
public Boolean getPosted() {
return posted;
}
public void setPosted(Boolean posted) {
this.posted = posted;
}
}
为了让网格访问数据,我提供了这个属性访问接口:
interface ListProperties extends PropertyAccess<InspectionListGridData> {
ValueProvider<InspectionListGridData, Boolean> posted();
}
Grid & column 配置声明如下:
final ListProperties properties = GWT.create(ListProperties.class);
final List<ColumnConfig<InspectionListGridData,?>> columnConfigList = new ArrayList<ColumnConfig<InspectionListGridData,?>>();
final ListStore<InspectionListGridData> store = new ListStore<InspectionListGridData>(
new ModelKeyProvider<InspectionListGridData>() {
@Override
public String getKey(InspectionListGridData item) {
return item.getInspectionDocumentId().toString();
}
}
});
final ColumnConfig<InspectionListGridData, Boolean> postedColumnConfig = new ColumnConfig<InspectionListGridData, Boolean>(properties.posted(), 5, "Posted");
ToggleButtonCell postedButtonCell = new ToggleButtonCell();
postedButtonCell.setText("posted");
postedButtonCell.setIcon(SafedoorPM.localizedResources.postedIcon());
postedButtonCell.setIconAlign(IconAlign.TOP);
postedColumnConfig.setCell(postedButtonCell);
postedColumnConfig.setSortable(false);
columnConfigList.add(postedColumnConfig);
Grid<InspectionListGridData> inspectionListGrid = new Grid<InspectionListGridData>(store, columnModel);
当我加载此屏幕时,按钮不会初始化为数据指示的相应状态。 [编辑:初始值加载失败是由于另一个错误。一旦我修复了正确加载的初始值]
加载屏幕后,如果我单击按钮,它会更改状态,但商店不会更新。我在 InspectionListGridData.setPosted() 方法上设置了断点,当我点击按钮时它不会被调用。
谁能看到我做错了什么?或者我认为这应该只是工作是错误的?我认为这就是 ValueProvider 接口的意义所在。
额外的怪异之处,网格在角落显示红色三角形,表示单击时单元格是脏的,并且按钮在单击时正确显示,即它保持向下或向上。它似乎没有读取或更新数据存储。
【问题讨论】:
-
嗯,代码看起来不错,假设 InspectionListGridData 有一个布尔属性 isPosted/getPosted/setPosted。我刚刚在本地调整了 sencha.com/examples/#ExamplePlace:inlineeditablegrid,以便在粘贴时或多或少地使用 ToggleButtonCell 而不是其 True/False 自定义单元格,它似乎表现得如预期......
-
一条线索:我的 ListStore 似乎没有设置为自动提交。我认为设置的一些花哨的代理/加载器可能已经禁用了它,所以我需要做一些手动提交。继续调查。
-
哦,哎呀,我看错了你的问题 - 我会在几个中发布部分答案,但你的部分问题仍然没有意义......