有没有人知道或者知道一个示例,它演示了使用Sencha GXT 3.0通过GWT RPC调用将数据加载到ListStore中?我知道有许多使用2.x版本中使用的ModelData和BeanModel接口的例子,但3.0不需要使用这些接口,并且假设允许使用实现ValueProperty接口的类加载POJO对象.
我在3.0资源管理器中看到了RequestFactoryBinding示例和RequestFactory Grid示例,但这些示例似乎演示了自定义数据代理和接收器的使用.我假设通过查看这些示例中的代码,可能需要这些技术/类,但这在任何地方都不明显.有可能会有更多文档即将发布,但到目前为止,我还没有找到除javadocs和Explorer之外的任何东西,缺少示例方法中使用的一些源类.
以下两个示例的链接.
RequestFactoryBinding示例:http://www.sencha.com/examples/#ExamplePlace :requestfactorybinding
RequestFactory Grid示例:http://www.sencha.com/examples/#ExamplePlace :requestfactorygrid
DataProxy并且Loader主要用于促进a)依赖服务器进行过滤/分页/排序,或b)在应用程序的各部分之间重用以获得对相同数据的访问.在客户端仅加载数据一次或手动存储管理完成的情况下,不需要它们(如2.x中所示).
各种商店加载类(ListStoreBinding,LoadResultListStoreBinding)在内部演示如何为ListStore提供项目.第一种方法允许您从onSuccessRPC回调或RequestFactory接收器中的方法替换存储中的现有项:
List<MyData> newItems = ...;//response from server
ListStore<MyData> store = ...;//current store to replace/update
store.replaceAll(newItems);
Run Code Online (Sandbox Code Playgroud)
如果仅加载一次,或仅附加,不替换,则应使用另一种方法:
store.addAll(newItems);
Run Code Online (Sandbox Code Playgroud)
可以使用逐个添加项目store.add,但这会导致每个项目发生一个事件,应该避免.
编辑:此外,这可能不完全清楚来自2.x,但数据本身不需要超类/接口.ValueProvider仅用作模型操作方式的外部抽象 - 如何通过任何类型的模型一般读取或设置值.该PropertyAccess接口允许ValueProvider(等),以仅由属性名称,该值将是获取/使用豆访问器设置来生成实例.加载数据不需要ValueProvider类型/实例,仅用于数据小部件本身提取它们正在显示的数据,并在用户编辑值后进行修改.
知道了这些部分,加载器/代理机制将以相同的基本方式加载数据.Loader负责被告知在加载时使用什么设置(分页,过滤和/或排序),然后触发加载 - 不同的子类具有不同的职责,接受不同的加载配置类型,并返回不同的结果.然后,DataProxy实际上与任何保存数据的内容进行通信,如果在服务器上异步,则通过回调通知加载器结果.
问题中列出的示例都使用RequestFactory,但也有几个使用RPC的示例,以及一些仅使用JSON或XML加载的示例.在http://www.sencha.com/examples/#ExamplePlace:paginggrid中,主要数据加载部分如下:
// 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));
Run Code Online (Sandbox Code Playgroud)