Javascript JSON存储可以';t加载PHP数据-ExtJS4

Javascript JSON存储可以';t加载PHP数据-ExtJS4,javascript,ajax,extjs,extjs4,store,Javascript,Ajax,Extjs,Extjs4,Store,我使用这段代码调用MarkerStore并传递参数mainid的值为1 Ext.define('GoogleMarkerModel', { extend: 'Ext.data.Model', fields: [ {name: 'ID', type: 'int'}, {name: 'Locating', type: 'int'}, {name: 'MainPower', type: 'int'},

我使用这段代码调用MarkerStore并传递参数mainid的值为1

Ext.define('GoogleMarkerModel', {
        extend: 'Ext.data.Model',
        fields: [
        {name: 'ID',    type: 'int'},
        {name: 'Locating',    type: 'int'},
        {name: 'MainPower',    type: 'int'},
        {name: 'Acc',    type: 'int'},
        {name: 'PowerOff',    type: 'int'},
        {name: 'Alarm',    type: 'int'},
        {name: 'Speed',    type: 'int'},
        {name: 'Direction',    type: 'int'},
        {name: 'Latitude',    type: 'float'},
        {name: 'Longitude',    type: 'float'},
        {name: 'DateTime',    type: 'date'},
        {name: 'MainID',    type: 'int'},
        {name: 'IOState',    type: 'int'},
        {name: 'OilState',    type: 'int'}]
    });

    var MarkerStore = Ext.create('Ext.data.JsonStore', {
        model: 'GoogleMarkerModel',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'get-googlemarker.php',
            baseParams: {  //here you can define params you want to be sent on each request from this store
                        mainid: 'value1'
                        },
            reader: {
                type: 'json',
                idProperty:'MainID',
            }

        }
    });
当我使用web浏览器获取-googlemarker.php时,mainid=1将返回这些值

MarkerStore.load({
                        params: {  //here you can define params on 'per request' basis
                                mainid: 1,
                                }
                        })
但我试图列出所有数据,不幸的是JSON存储为空,我怀疑数据没有存储在MarkerStore中,下面的代码是我试图列出的数据,但没有写在控制台FireBug上

http://localhost/GPS/examples/tabs/get-googlemarker.php?mainid=1

[{"ID":"1808","Locating":"1","MainPower":"0","Acc":"1","PowerOff":"1","Alarm":"128","Speed":"0","Direction":"293","Latitude":"5.391788482666016","Longitude":"100.29693603515625","DateTime":"2013-02-19 15:44:36","MainID":"1","IOState":"0","OilState":"0"}]

有什么想法吗?

尝试从存储中删除
autoload=true
属性。

MarkerStore.on('load',函数(存储,记录){
MarkerStore.each( function (model) {
    console.log( model.get('MainID') ); 
    }); 
对于(var i=0;i

如果使用此代码,则将在控制台上打印数据。上面的问题打印存储数据代码是错误的,实际上数据是成功保存在JSON存储中的

您的代码工作正常,但主要问题是调用MarkerStore时。此时存储中的每个数据都是空的(Ajax是异步的)。您的脚本与ajax处理数据的速度一样快。如果您使用以下简单代码段,您将看到您的“mainID”

MarkerStore.on('load', function(store, records) {
    for (var i = 0; i < records.length; i++) {
    console.log(records[i].get('Latitude'));
    lati = records[i].get('Latitude'); 
    };
});
setTimeout(function(){
        MarkerStore.each( function (model) {
                console.log( model.get('MainID') );
        });     
    }, 1500, MarkerStore);