Extjs 如何将服务器中的记录索引检索到Sencha Touch 2应用程序中,然后检索完整的模型实例
设置Sencha Touch 2存储来检索少量数据以从jsonp响应生成多个模型实例可能很简单。然而,我正在开发一个应用程序,它可以处理服务器上相当大的数据集(法律意见),因此我必须从服务器上检索一个可用记录的列表——如果你愿意的话,这是一个索引——然后当用户点击列表中的项目时检索一个完整的记录 我正在寻找任何推荐的方法来做到这一点。以下是我到目前为止设置的,仅部分起作用:Extjs 如何将服务器中的记录索引检索到Sencha Touch 2应用程序中,然后检索完整的模型实例,extjs,sencha-touch,sencha-touch-2,Extjs,Sencha Touch,Sencha Touch 2,设置Sencha Touch 2存储来检索少量数据以从jsonp响应生成多个模型实例可能很简单。然而,我正在开发一个应用程序,它可以处理服务器上相当大的数据集(法律意见),因此我必须从服务器上检索一个可用记录的列表——如果你愿意的话,这是一个索引——然后当用户点击列表中的项目时检索一个完整的记录 我正在寻找任何推荐的方法来做到这一点。以下是我到目前为止设置的,仅部分起作用: 我在服务器端定义了:index和:show RESTful操作来检索法律意见 在客户端,我有一个索引项的模型和存储(包括我
# Controller:
onDisplayAuthority: function(list, record) {
console.log('onDisplayAuthority');
this.activateAuthorityView(record);
var authorityView = this.getAuthorityView();
authorityStore = Ext.getStore('Authority');
var authorityId = record.getData().id;
var url = 'http://localhost:3000/api/authorities/' + authorityId + '.json';
var proxy = {
type: 'jsonp',
url: url,
reader: {
type: 'json',
rootProperty: "authority"
}
};
authorityStore.setProxy(proxy);
authorityStore.load();
authority = authorityStore.first();
var data = authority.getData();
authorityView.setRecord(authority);
authorityView.getComponent("authorityViewBody").setData(data);
authorityView.getComponent("titlebar").setTitle(data.title);
Ext.Viewport.animateActiveItem(authorityView, this.slideLeftTransition);
}
console.log(authorityStore)
,我可以看到authorityStore.data.all[0]
包含完整的法律意见。但是,当我运行console.log(authorityStore.data.all[0])
时,它返回[]
。此外,authorityStore.first()
返回未定义的
,尽管Sencha Touch 2文档显示#first()
是有效存储的方法,而authorityStore
是有效存储
所以,要么我错过了一些基本的东西,要么我在这方面偏离了常规
是否有人(i)对我的问题有一个快速的解决方案,或者(ii)使用另一种方法:index:和:show actions来减少无关的数据传输?这很有效:
onDisplayAuthority: function(list, record) {
console.log('onDisplayAuthority');
var authorityView = this.getAuthorityView();
authorityStore = Ext.getStore('Authority');
var authorityId = record.getData().id;
var url = 'http://localhost:3000/api/authorities/' + authorityId + '.json';
var proxy = {
type: 'jsonp',
url: url,
reader: {
type: 'json',
rootProperty: "authority"
}
};
authorityStore.setProxy(proxy);
authorityStore.load({
callback: function(records, operation, success) {
// the operation object contains all of the details of the load operation
var data = records[0].getData();
authorityView.setRecord(records[0]);
authorityView.getComponent("authorityViewBody").setData(data);
authorityView.getComponent("titlebar").setTitle(data.title);
},
scope: this});
Ext.Viewport.animateActiveItem(authorityView, this.slideLeftTransition);
}
通过将为authorityView
设置数据的代码行放在存储的#load方法的回调中,我能够访问新记录。我不知道为什么我必须这样做,并将感谢评论。但是,这种方法确实有效