Extjs中Store的load方法???

1988_1989 2011-12-01 03:43:42
Ext.data.Store的load方法的参数中callback回调函数有三个参数,
r : Ext.data.Record[]
options: 加载的配置项对象。Options object from the load call
success: 是否成功。Boolean success indicator


第一个参数如何得到record的id

数据源代码如下:
	
this.Record = Ext.data.Record.create([
{name: 'caPk', mapping: 'caPk'},
{name: 'caPatientId', mapping: 'caPatientId'},
{name: 'caVisitId', mapping: 'caVisitId'},
{name: 'caInpNo', mapping: 'caInpNo'},
{name: 'caName', mapping: 'caName'},
{name: 'caAge', mapping: 'caAge'},
{name: 'caSex', mapping: 'caSex'},
{name: 'caBloodType', mapping: 'caBloodType'},
{name: 'caDeptCode', mapping: 'caDeptCode'},
{name: 'caMainDiagnose', mapping: 'caMainDiagnose'},
{name: 'opName', mapping: 'opName'}
]);

// 数据源代理
this.dataProxy = new Ext.data.HttpProxy({
url:'cbi/manage/index/list.do'

});

var store = new Ext.data.JsonReader({
root:'data',
totalProperty:'count',
id: 'caPk'
}, this.Record)
// 创建数据源
this.ds = new Ext.data.Store({
proxy:this.dataProxy,
autoLoad:false,
listeners:{
datachanged:clearAllSelectedcheckBox
},
reader: store
});
在Grid加载数据源时:
this.ds.load({
params:{start:0,limit:15},
callback:function(r,options,success){
if(success){
var records = new Array();
for(var i=0;i<=r.length;i++){
alert(r[i].data.caPk);
//得到id之后用于其他判断
};
//selModel.selectRecords(records,true);//每次load数据时,都要默认选中
}
},
scope:this

});





现在就是想得到r中每个Record中的caPk(主键)。
高手帮帮忙。。。。。。。。。。。。。。。。。。

...全文
6132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
1988_1989 2011-12-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hookee 的回复:]

i<=r.length 这里要改, 不要=
load只有 params:{start:0,limit:15} 参数变化, 才会将重新加载并调用回调函数
[/Quote]

看了看PagingToolBar的源码,
他的onload方法中,
  // private
onLoad : function(store, r, o){
if(!this.rendered){
this.dsLoaded = [store, r, o];
return;
}
var p = this.getParams();
this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
var d = this.getPageData(), ap = d.activePage, ps = d.pages;

this.afterTextItem.setText(String.format(this.afterPageText, d.pages));
this.inputItem.setValue(ap);
this.first.setDisabled(ap == 1);
this.prev.setDisabled(ap == 1);
this.next.setDisabled(ap == ps);
this.last.setDisabled(ap == ps);
this.refresh.enable();
this.updateInfo();
this.fireEvent('change', this, d);
},


this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;

这句话是什么作用呢?
1988_1989 2011-12-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hookee 的回复:]

i<=r.length 这里要改, 不要=
load只有 params:{start:0,limit:15} 参数变化, 才会将重新加载并调用回调函数
[/Quote]

this.ds.load({params:{start:0,limit:15}});第一次加载时必须要传start和limit,
如果不传,数据加载不到,

如何让params:{start:0,limit:15} 参数变化?????

我想要在加载本页的记录完成后,取出这些记录。然后做一些特殊处理,
hookee 2011-12-03
  • 打赏
  • 举报
回复
如果没有设置start, 则cursor 设为0, 否则 cursor = start
hookee 2011-12-02
  • 打赏
  • 举报
回复
i<=r.length 这里要改, 不要=
load只有 params:{start:0,limit:15} 参数变化, 才会将重新加载并调用回调函数
1988_1989 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hookee 的回复:]

alert(r[i].get("caPk"));
[/Quote]
 this.ds.load({
params:{start:0,limit:15},
callback:function(r,options,success){
if(success){
var records = new Array();
for(var i=0;i<=r.length;i++){
alert(r[i].data.caPk);
//得到id之后用于其他判断
};
//selModel.selectRecords(records,true);//每次load数据时,都要默认选中
}
},
scope:this

});

这个load只有在第一次加载时运行,之后就不会再执行了,

Grid是一个分页的表格,
每次翻页时,都是执行this.dataProxy的beforeload方法,
现在我想要在点击翻页后,load完下一页的数据后得到这些records.
我该怎么做?????????
在哪里监听事件,,,,,,

    //加载数据之前,传递参数
this.dataProxy.on("beforeload", function(proxy, params) {
params.keyWord = this.keyWord;
params.caMainDept = this.caMainDept;
params.caDeptCode = this.caDeptCode;
params.caMainDiagnose = Ext.encode(this.caMainDiagnose);
params.level = this.level;
params.searchArray = this.searchArray;
}.createDelegate(this));
东方2009 2011-12-01
  • 打赏
  • 举报
回复
添上 model : remote试试
jungool 2011-12-01
  • 打赏
  • 举报
回复
data.records[i].get('caPk')试下
hookee 2011-12-01
  • 打赏
  • 举报
回复
循环也不对,i<r.length
for(var i=0;i<r.length;i++){
alert(r[i].get("caPk"));
};
hookee 2011-12-01
  • 打赏
  • 举报
回复
alert(r[i].get("caPk"));

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧