开发者

Sencha: Iterating a list store of a custom BaseModel subclass

开发者 https://www.devze.com 2023-03-02 18:20 出处:网络
I just started playing with Sencha\'s Ext GWT yesterday and I\'ve hit a wall. I combined methods from their JSON loaded grid and their editable grid.As a test data set I\'m using a list of Stargate At

I just started playing with Sencha's Ext GWT yesterday and I've hit a wall. I combined methods from their JSON loaded grid and their editable grid. As a test data set I'm using a list of Stargate Atlantis episodes hence the SGAEpisode which is defined as:

public class SGAEpisode extends BaseModel {
  public SGAEpisode() {

  }

  public SGAEpisode(String season, String episode) {
    set("season",season);
    set("episode",episode);
  }

  public void setSeason(String season) {
    set("season",season);
  }

  public String getSeason(){
    return get("season");
  }

  public void setEpisode(String name) {
    set("episode",name);
  }

  public String getEpisode() {
    return get("episode");
  }

  public String toString() {
    return "Season: " + get("season") + " episode: " + get("episode");
  }
} 

the onModuleLoad() starts off with...

ModelType type = new ModelType();
type.setRoot("seasons");
type.addField("Season","season");
type.addField("Episode","episode");

String path = GWT.getHostPageBaseURL() + "senchaapp/sgaepisodes";

final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,path);
final MVProxy<String> proxy = new SP开发者_开发问答roxy<String>(builder);

JsonLoadResultReader<ListLoadResult<SGAEpisode>> reader = new JsonLoadResultReader<ListLoadResult<SGAEpisode>>(type);
final BaseListLoader<ListLoadResult<SGAEpisode>> loader = new BaseListLoader<ListLoadResult<SGAEpisode>>(proxy,reader);

final ListStore<SGAEpisode> episodes = new ListStore<SGAEpisode>(loader);

so loader.load() works great, populating a grid, I can edit fields, but I don't see commitChanges() doing anything and I can't iterate over the ListStore "episodes" to gather changed or added values. Oh, and SProxy is just a DataProxy subclass to allow me to specify the season's JSON I'm loading into the grid.

If I try either

for(SGAEpisode episode : episodes) {
  save(episode);
}

or

for(int i = 0; i < episodes.getCount(); i++) {
  save(episodes.getAt(i));
}

I get an exception with the message "com.extjs.gxt.ui.client.data.BaseModel cannot be cast to com.mvsc.sencha.shared.SGAEpisode" Any idea what I'm doing wrong? Everything up to that point was defined/populated with SGAEpisodes.....

Addendum Ok, so if I try

List<Record> modified = episodes.getModifiedRecords();

for(Record r : modified) {
  ModelData md = r.getModel();
  save(md.get("season"),md.get("episode")); 
}

I can iterate, and get the modified values, but what's the point of having a ModelData subclass if I have to use the base class like this. Which makes me think I don't in fact have to..... little help?

Addendum 2 I tried subclassing BaseModelData instead with no success.


I know its an older post, I had the same issue. This is how I fixed it. try iterating through the models in listStore.

for(SGAEpisode episode : episodes.getModels()) {
    save(episode);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消