使用GWT RPC调用将数据加载到Sencha GXT(3.0)ListStore的简单示例?
有人知道或有人知道使用Sencha GXT3.0通过GWT RPC调用将数据加载到ListStore的示例吗?我知道在2.x版本中有很多使用ModelData和BeanModel接口的例子,但是3.0不再需要使用这些接口,并且假定允许使用实现ValueProperty接口的类加载POJO对象 我在3.0浏览器中看到了RequestFactoryBinding示例和RequestFactory网格示例,但它们似乎演示了自定义数据代理和接收器的使用。通过查看这些示例中的代码,我假设这些技术/类可能是必需的,但在任何地方都不明显。可能会有更多的文档即将发布,但到目前为止,除了javadocs和Explorer之外,我还没有找到更多的东西,因为它缺少示例方法中使用的一些源类 下面两个例子的链接 RequestFactoryBinding示例: RequestFactory网格示例:使用GWT RPC调用将数据加载到Sencha GXT(3.0)ListStore的简单示例?,gwt,extjs,rpc,gxt,Gwt,Extjs,Rpc,Gxt,有人知道或有人知道使用Sencha GXT3.0通过GWT RPC调用将数据加载到ListStore的示例吗?我知道在2.x版本中有很多使用ModelData和BeanModel接口的例子,但是3.0不再需要使用这些接口,并且假定允许使用实现ValueProperty接口的类加载POJO对象 我在3.0浏览器中看到了RequestFactoryBinding示例和RequestFactory网格示例,但它们似乎演示了自定义数据代理和接收器的使用。通过查看这些示例中的代码,我假设这些技术/类可能是
DataProxy
和Loader
主要用于帮助a)依赖服务器进行筛选/分页/排序,或b)在应用程序的各个部分之间重用以访问相同的数据段。如果客户机只加载一次数据,或者执行了手动存储管理,则不需要它们(如2.x中所示)
各种存储加载类(ListStoreBinding
,LoadResultListStoreBinding
)在内部演示了如何为列表存储提供项目。第一种方法允许您从RPC回调或RequestFactory接收器中的onSuccess
方法替换存储中的现有项:
List<MyData> newItems = ...;//response from server
ListStore<MyData> store = ...;//current store to replace/update
store.replaceAll(newItems);
可以使用store.add
逐个添加项目,但这将导致每个项目发生事件,应避免
编辑:同样,对于2.x来说,这可能并不完全清楚,但数据本身不需要超类/接口ValueProvider
仅用作如何操作模型的外部抽象—如何从任何类型的模型中读取或设置值。PropertyAccess
接口允许仅通过使用bean访问器获取/设置值的属性名生成ValueProvider
(和其他)实例。加载数据不需要ValueProvider类型/实例,只需要数据小部件本身提取它们正在显示的数据,并在用户编辑值后进行修改
知道了这些部分,加载器/代理机制将以相同的基本方式加载数据。加载程序负责在加载时被告知要使用什么设置(分页、筛选和/或排序),然后触发加载-不同的子类有不同的职责,接受不同的加载配置类型,并返回不同的结果。DataProxy则是一种机制,它实际上与保存数据的任何对象进行对话,如果在服务器上,则是异步的,并在结果通过回调可用时通知加载程序 问题中列出的示例都使用RequestFactory,但也有一些示例使用RPC,还有一些仅从JSON或XML加载。主要数据加载部分如下:
// The rpc async instance
final ExampleServiceAsync service = GWT.create(ExampleService.class);
// As in Ext GWT 2, there is a convenience proxy for RPC to just pass the callback
// directly to the RPC call. If you need a custom callback, just be sure to invoke
// `callback.onSuccess` with the final result.
RpcProxy<PagingLoadConfig, PagingLoadResult<Post>> proxy = new RpcProxy<PagingLoadConfig, PagingLoadResult<Post>>() {
@Override
public void load(PagingLoadConfig loadConfig, AsyncCallback<PagingLoadResult<Post>> callback) {
service.getPosts(loadConfig, callback);
}
};
// ...
// The loader itself has a reference to the proxy so that loader.load() results
// in a round trip to the server, as outlined above.
final PagingLoader<PagingLoadConfig, PagingLoadResult<Post>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<Post>>(
proxy);
loader.setRemoteSort(true);
// This last piece - instead of 2.x where the loader is a parameter to the store,
// in 3 you directly wire the results of the loader to add the items into the
// store, as discussed in the first half of this answer
loader.addLoadHandler(new LoadResultListStoreBinding<PagingLoadConfig, Post, PagingLoadResult<Post>>(store));
//rpc异步实例
final-ExampleServiceAsync service=GWT.create(ExampleService.class);
//与extgwt2一样,RPC有一个方便的代理来传递回调
//直接发送到RPC调用。如果需要自定义回调,请确保调用
//'callback.onSuccess`和最终结果。
RpcProxy代理=新的RpcProxy(){
@凌驾
公共无效加载(分页加载配置、异步回调){
getPosts(loadConfig,回调);
}
};
// ...
//加载器本身有一个对代理的引用,因此loader.load()会产生
//在到服务器的往返过程中,如上所述。
最终分页加载器=新分页加载器(
委托书);
loader.setRemoteSort(true);
//这是最后一个片段-而不是2.x,其中加载程序是存储的一个参数,
//在3中,您直接连接加载器的结果,以将项目添加到
//存储,如本答案前半部分所述
addLoadHandler(新的LoadResultListStoreBinding(store));
FWIW我在一个远程分页和排序的网格上加了一个峰值。这是带有命令模式扭曲的GWT RPC
假设您熟悉网格,则需要以下实例:
RpcProxy
PagingLoader
LoadResultListStoreBinding
PagingLoader.setRemoteSort(true)
PagingLoader.addLoadHandler()
Grid.setLoader()
PagingToolBar.bind()
// The rpc async instance
final ExampleServiceAsync service = GWT.create(ExampleService.class);
// As in Ext GWT 2, there is a convenience proxy for RPC to just pass the callback
// directly to the RPC call. If you need a custom callback, just be sure to invoke
// `callback.onSuccess` with the final result.
RpcProxy<PagingLoadConfig, PagingLoadResult<Post>> proxy = new RpcProxy<PagingLoadConfig, PagingLoadResult<Post>>() {
@Override
public void load(PagingLoadConfig loadConfig, AsyncCallback<PagingLoadResult<Post>> callback) {
service.getPosts(loadConfig, callback);
}
};
// ...
// The loader itself has a reference to the proxy so that loader.load() results
// in a round trip to the server, as outlined above.
final PagingLoader<PagingLoadConfig, PagingLoadResult<Post>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<Post>>(
proxy);
loader.setRemoteSort(true);
// This last piece - instead of 2.x where the loader is a parameter to the store,
// in 3 you directly wire the results of the loader to add the items into the
// store, as discussed in the first half of this answer
loader.addLoadHandler(new LoadResultListStoreBinding<PagingLoadConfig, Post, PagingLoadResult<Post>>(store));