使用 EXT-GWT 组合框

发布于 2024-10-31 13:31:38 字数 873 浏览 1 评论 0原文

我扩展 ComboBox 并在构造函数中具有这样的代码:

ModelType type = new ModelType();  
type.setRoot("data");
type.addField("id", "id");
type.addField("name", "name");

JsonLoadResultReader<ListLoadResult<ModelData>> reader = new JsonLoadResultReader<ListLoadResult<ModelData>>(type);

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/category/getall");
HttpProxy<String> proxy = new HttpProxy<String>(builder);

BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);

ListStore<ModelData> store = new ListStore<ModelData>(loader);


setStore(store);
loader.load();
setValueField("id");
setDisplayField("name");
setName("categoty");

结果:ajax 查询发送到服务器但在组合框中看不到结果,但是当单击它时它会再次加载数据然后显示它,以及如何将值设置为组合框?

I extend ComboBox and in constructor have such code:

ModelType type = new ModelType();  
type.setRoot("data");
type.addField("id", "id");
type.addField("name", "name");

JsonLoadResultReader<ListLoadResult<ModelData>> reader = new JsonLoadResultReader<ListLoadResult<ModelData>>(type);

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/category/getall");
HttpProxy<String> proxy = new HttpProxy<String>(builder);

BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);

ListStore<ModelData> store = new ListStore<ModelData>(loader);


setStore(store);
loader.load();
setValueField("id");
setDisplayField("name");
setName("categoty");

Result: ajax query send to server but no results see in combobox but when click on it it loads data again and then display it, and how to set value to combobox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送君千里 2024-11-07 13:31:39

我创建了一个简单的商店工厂方法,应该可以解决您的问题。
复制您的类并创建商店:

setStore(_createListStore("/category/getall", "data", "id", "name"));
loader.load();
setValueField("id");
setDisplayField("name");
setName("categoty");

代码中的错误是您向 ModelType 添加了两个字段,而您应该只添加一个字段,其中“id”作为值,“name”作为显示

protected ListStore<ModelData> _createListStore(String url, String root, String fieldValue, String displayValue){
    ModelType mt = new ModelType();
    mt.setRoot(root);
    mt.addField(displayValue, fieldValue);
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    HttpProxy<String> proxy = new HttpProxy<String>(rb);
    JsonLoadResultReader<ListLoadResult<ModelData>> reader = new JsonLoadResultReader<ListLoadResult<ModelData>>(mt);
    final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
    ListStore<ModelData> store = new ListStore<ModelData>(loader);
    return store;
}

I've created a simple store factory method that should solve your issue.
Copy in your class and create the store:

setStore(_createListStore("/category/getall", "data", "id", "name"));
loader.load();
setValueField("id");
setDisplayField("name");
setName("categoty");

the error in your code is that you add two fields to the ModelType, instead you should add just one field with "id" as value and "name" as display

protected ListStore<ModelData> _createListStore(String url, String root, String fieldValue, String displayValue){
    ModelType mt = new ModelType();
    mt.setRoot(root);
    mt.addField(displayValue, fieldValue);
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    HttpProxy<String> proxy = new HttpProxy<String>(rb);
    JsonLoadResultReader<ListLoadResult<ModelData>> reader = new JsonLoadResultReader<ListLoadResult<ModelData>>(mt);
    final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
    ListStore<ModelData> store = new ListStore<ModelData>(loader);
    return store;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文