我扩展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查询发送到服务器但没有结果在组合框中看到,但是当点击它时它再次加载数据然后显示它,以及如何设置组合框的值?
答案 0 :(得分:0)
我已经创建了一个简单的商店工厂方法,可以解决您的问题。 在课堂上复制并创建商店:
setStore(_createListStore("/category/getall", "data", "id", "name"));
loader.load();
setValueField("id");
setDisplayField("name");
setName("categoty");
代码中的错误是您向ModelType添加了两个字段,而您应该只添加一个带有&#34; id&#34;的字段。作为价值和&#34;名称&#34;作为显示
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;
}