Extjs 如何将服务器中的记录索引检索到Sencha Touch 2应用程序中,然后检索完整的模型实例

Extjs 如何将服务器中的记录索引检索到Sencha Touch 2应用程序中,然后检索完整的模型实例,extjs,sencha-touch,sencha-touch-2,Extjs,Sencha Touch,Sencha Touch 2,设置Sencha Touch 2存储来检索少量数据以从jsonp响应生成多个模型实例可能很简单。然而,我正在开发一个应用程序,它可以处理服务器上相当大的数据集(法律意见),因此我必须从服务器上检索一个可用记录的列表——如果你愿意的话,这是一个索引——然后当用户点击列表中的项目时检索一个完整的记录 我正在寻找任何推荐的方法来做到这一点。以下是我到目前为止设置的,仅部分起作用: 我在服务器端定义了:index和:show RESTful操作来检索法律意见 在客户端,我有一个索引项的模型和存储(包括我

设置Sencha Touch 2存储来检索少量数据以从jsonp响应生成多个模型实例可能很简单。然而,我正在开发一个应用程序,它可以处理服务器上相当大的数据集(法律意见),因此我必须从服务器上检索一个可用记录的列表——如果你愿意的话,这是一个索引——然后当用户点击列表中的项目时检索一个完整的记录

我正在寻找任何推荐的方法来做到这一点。以下是我到目前为止设置的,仅部分起作用:

  • 我在服务器端定义了:index和:show RESTful操作来检索法律意见
  • 在客户端,我有一个索引项的模型和存储(包括我的可用数据列表),它们通过jsonp响应从服务器上的:index RESTful操作中提取数据,以在列表组件中创建可用数据的索引。这些索引条目中的字段不包含法律意见书全文,而仅包含当事人姓名和引文
  • 我有一个完整的法律意见模型和商店。商店通过:在服务器上显示RESTful操作一次从服务器获取一个法律意见
  • 当用户点击应用程序中法律意见列表中的一个项目时,监听器会触发一个事件,控制器会拾取该事件。控制器使用列表项对应记录的ID来确定服务器上:show操作的正确URL,如下所示:

        # 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方法的回调中,我能够访问新记录。我不知道为什么我必须这样做,并将感谢评论。但是,这种方法确实有效