Code Snippet

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ExtJS 3中Store组件默认是异步加载的,文档中建议使用事件来解决同步加载的问题。

借助jQuery我们可以实现同步加载Store。

进一步,把这句jQuery.ajax调用扩展到Store的方法中那更愉快了,比如直接调用SyncStore.SyncLoad(); 本文就不继续了

var recUser = Ext.data.Record.create([
{name :
'id',mapping : 'id',type : 'int'},
{name :
'name',mapping : 'name',type : 'string'},
{name :
'passwd',mapping : 'passwd',type : 'string'}
]);


var dsUser = new Ext.data.Store({
url: contextPath
+ '/listUserByIds.action',
baseParams: {start:
0, limit: 256},
reader:
new Ext.data.JsonReader({
totalProperty:
'totalProperty',
root:
'root'
}, recUser)
});


jQuery.ajax({
'url': dsUser.url, 'async': false, 'dataType': 'json', 'data': dsUser.baseParams,
'success': function(data){
if (typeof data.totalProperty == 'undefined' ||
data.totalProperty
== 0 ||
typeof data.root == 'undefined'
) {
return;
}
for (var i = 0, len = data.root.length; i < len; i++) {
dsUser.add(
new recUser(data.root[i]));
}
}
});
posted on 2011-03-09 10:34  kmlxk  阅读(2505)  评论(0编辑  收藏  举报