- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 GXT 3 应用程序,我正在尝试使用 ToggleButtonCell 来允许用户修改 boolean 值。
这是数据的代码:
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):
interface ListProperties extends PropertyAccess<InspectionListGridData> {
ValueProvider<InspectionListGridData, Boolean> posted();
}
网格和列配置声明如下:
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 接口(interface)的要点。
额外的奇怪之处是,网格在角落显示红色三角形,表示单击时单元格是脏的,并且按钮在单击时确实显示正确,即它保持向下或向上状态。它似乎只是不读取或更新数据存储。
最佳答案
这里有两个问题,一开始我只回答了第一个问题(我仍然无法回答,但更多信息可能会有所帮助),但第二个问题非常清楚。
When I load this screen, the buttons do not initialize to the corresponding state indicated by the data.
这很令人困惑,并且与我放在一起的快速示例相矛盾,正如我在评论中指出的那样,这可能是您在绘制网格后更改数据并且没有通知商店或网格数据已更改,但是如果您使用 true 和 false 值构建数据,则网格应该显示 true 和 false 值。
I set breakpoint on the InspectionListGridData.setPosted() method, it is not called when I click on the button.
默认情况下,这是预期的,而 store.isAutoCommmit()
为 true,这是默认值。这告诉存储它应该对更改进行排队,而不是将它们直接应用于存储中的对象。这些更改的值在 UI 中用您注意到的红色三角形标记,其他代码可以通过 Store.getRecord(M)
检查更改的值。方法或Store.getModifiedRecords()
来电。调用store.commitChanges()
会将它们全部应用于底层模型,或者您可以使用 Record.commit()
致力于特定模型。您还可以使用 Store.rejectChanges()
拒绝更改或Record.revert()
.
关闭此功能后,应通过单击按钮来调用 setPosted 方法。不会发生任何更改跟踪,因此不会设置脏标志,无论是在视觉上还是在商店的记录中。
如果您更改已渲染的对象,您有两个(主要)选择 - 您可以直接通过其 setter 修改该对象并通知存储,或者您可以使用存储的记录对象。如果自动提交为 false 并且您调用 store.getRecord(object).addChange(properties.posted(), true)
,然后这将调用 setPosted(true)
,而不是创建要提交的新更改。 ,因此当自动提交为 false 时,这些方法实际上是相同的。如果直接调用 setter,请务必通过 store.update
通知 store 对象已更改。 .
关于java - GXT 3 ToggleButtonCell 不更新数据存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22672699/
我有一个 GXT 3 应用程序,我正在尝试使用 ToggleButtonCell 来允许用户修改 boolean 值。 这是数据的代码: public class InspectionListGrid
我是一名优秀的程序员,十分优秀!