如何在ext gwt中实现ModelData接口?
我正在尝试在我正在进行的项目中使用 EditorGrid。我正在使用 EditorGrid grid = new EditorGrid (...)
ClassGrade 是一个对象,其中包含班级的名称、成绩(作为 Grade 对象)和学时。
但是,ClassGrade 必须实现 ModelData。当我尝试实现该接口时,有一些方法我不确定如何正确实现。
@Override
public <X> X get(String property) {
if (property.equals("name"))
return this.getClassName();
if (property.equals("hours"))
return this.getHours();
if (property.equals("grade"))
return this.getGrade();
return null;
}
@Override
public Map<String, Object> getProperties() {
Map<String, Object> propMap = new HashMap<String, Object>();
propMap.put("grade", this.getGrade());
propMap.put("hours", this.getHours());
propMap.put("name", this.getClassName());
return propMap;
}
@Override
public Collection<String> getPropertyNames() {
ArrayList<String> props = new ArrayList<String>();
props.add("grade");
props.add("hours");
props.add("name");
return props;
}
@Override
public <X> X remove(String property) {
// TODO Auto-generated method stub
return null;
}
@Override
public <X> X set(String property, X value) {
// TODO Auto-generated method stub
return null;
}
我不知道如何处理 get、remove 和 set 方法,因为我不知道 X 的含义。我尝试使用,
@Override
public <X> X get(String property) {
if (property.equals("name"))
return this.getClassName();
if (property.equals("hours"))
return this.getHours();
if (property.equals("grade"))
return this.getGrade();
return null;
}
但这不起作用,因为返回的不是 X 类型。我做错了什么以及如何让它工作?
I am trying to use an EditorGrid in a project that I am working on. I am using
EditorGrid grid = new EditorGrid (...)
ClassGrade is an object that contains the name, grade (as a Grade object), and credit hours for a class.
However, ClassGrade must implement ModelData. When I tried to implement the interface, there are a few methods that I am not sure how to correctly implement.
@Override
public <X> X get(String property) {
if (property.equals("name"))
return this.getClassName();
if (property.equals("hours"))
return this.getHours();
if (property.equals("grade"))
return this.getGrade();
return null;
}
@Override
public Map<String, Object> getProperties() {
Map<String, Object> propMap = new HashMap<String, Object>();
propMap.put("grade", this.getGrade());
propMap.put("hours", this.getHours());
propMap.put("name", this.getClassName());
return propMap;
}
@Override
public Collection<String> getPropertyNames() {
ArrayList<String> props = new ArrayList<String>();
props.add("grade");
props.add("hours");
props.add("name");
return props;
}
@Override
public <X> X remove(String property) {
// TODO Auto-generated method stub
return null;
}
@Override
public <X> X set(String property, X value) {
// TODO Auto-generated method stub
return null;
}
I dont know what to do for the get, remove, and set methods, because I do not know what the X means. I tried using
@Override
public <X> X get(String property) {
if (property.equals("name"))
return this.getClassName();
if (property.equals("hours"))
return this.getHours();
if (property.equals("grade"))
return this.getGrade();
return null;
}
but that didn't work because the return was not of type X. What am I doing wrong and how do I get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还使用网格等,并使用 BeanModel 类来存储需要 modelData 的商店。我的实现如下。
并将
该对象转换为模型,如下所示;
我希望它对你有用。
I also use grids etc. and use BeanModel class for stores which wants modelData. I implement as below.
and
convert this object to model as below;
I hope it is useful for you.