【问题标题】:Sencha touch store - phantom dataSencha touch store - 幻影数据
【发布时间】:2012-12-22 03:24:54
【问题描述】:

我创建了一个类似的模型

Ext.define('MyApp.model.ContainerDetailsModel', {
extend: 'Ext.data.Model',
alias: 'model.ContainerDetailsModel',
config: {
    fields: [
        {
            name: 'id',
            allowNull: false,
            type: 'string'
        },
        {
            name: 'container_types_id',
            type: 'string'
        }
    ]
  }
});

还有这样的商店

Ext.define('MyApp.store.ContainerDetailsStore', {
extend: 'Ext.data.Store',

requires: [
    'MyApp.model.ContainerDetailsModel'
],

config: {
    model: 'MyApp.model.ContainerDetailsModel',
    storeId: 'ContainerDetailsStore',
    proxy: {
        type: 'ajax',
        enablePagingParams: false,
        url: 'hereIsServiceUrl',
        reader: {
            type: 'json'
        }
    }
}
});

现在在应用程序的某个地方,我试图获取一条记录,例如:

var detailsStore = Ext.getStore("ContainerDetailsStore");
detailsStore.load();
var detailsRecord = detailsStore.last();

但它给了我不确定性。服务返回的 json 是可以的,它在不同的地方使用它作为列表的源。我已经尝试将 allowNull 更改为 true,但源中没有 null id。我尝试将类型设置为“int”,结果相同。

所以我试过了

console.log(detailsStore);

结果是这样的(只是重要的值):

Class {
...
loaded: true,
data: Class {
   ...
   all: Array[1] {
       length: 1,
       0: Class {
           container_types_id: "1",
           id: "726",
           ....
       }
   ...
   }
   ...
},
...
}

在同一个地方

 console.log(detailsStore.data);

返回(应该如此):

 Class {
   ...
   all: Array[1] {
       length: 1,
       0: Class {
           container_types_id: "1",
           id: "726",
           ....
       }
   ...
   }

但是(下一行)

console.log(detailsStore.data.all);

返回

 []

而且它是空数组。当我从商店尝试任何方法时,它说商店是空的。 我一个接一个地写了 console.log() 行 - 所以确保它们之间不会改变(我也尝试以不同的顺序或组合)。

我的浏览器是 Google Chrome 23.0.1271.97 m 我使用来自https://extjs.cachefly.net/touch/sencha-touch-2.0.1.1/sencha-touch-all-debug.js的煎茶

我如何从那家商店获取唱片?

【问题讨论】:

    标签: javascript google-chrome sencha-touch store


    【解决方案1】:

    store.load() 通过配置的代理将数据加载到存储中。这使用代理对代理使用的任何存储后端进行异步调用,自动将检索到的实例添加到存储中,并在需要时调用可选的回调。但是,该方法在获取数据之前返回。因此回调函数,执行操作存储中的新数据的逻辑。 试试吧,

    detailsStore.load({
        callback: function(records, operation, success) {
        var detailsRecord = detailsStore.last();
        },
        scope: this
    });
    

    【讨论】:

    • 非常感谢这个解决方案。
    猜你喜欢
    • 1970-01-01
    • 2011-11-26
    • 2014-02-06
    • 2012-02-22
    • 2012-08-18
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2011-11-24
    相关资源
    最近更新 更多