Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/479.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSON记录计数返回0?ExtJS4_Javascript_Ajax_Json_Extjs_Extjs4 - Fatal编程技术网

Javascript JSON记录计数返回0?ExtJS4

Javascript JSON记录计数返回0?ExtJS4,javascript,ajax,json,extjs,extjs4,Javascript,Ajax,Json,Extjs,Extjs4,这是firebug中的记录返回,我正在尝试使用alert(MarkerStore.getCount())对记录进行计数返回0?为什么? 我仔细检查了字段名,所有字段都是正确的。这是怎么回事 Ext.define('GoogleMarkerModel', { extend: 'Ext.data.Model', fields: ['ID','Locating','MainPower','Acc','PowerOff','Alarm','Speed','Directio

这是firebug中的记录返回,我正在尝试使用
alert(MarkerStore.getCount())对记录进行计数返回0?为什么?
我仔细检查了字段名,所有字段都是正确的。这是怎么回事

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

    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',
            }

        }
    });

MarkerStore.load({
params: {  
        mainid: 1,
        }
})
更新
我已经添加了idproperty,但仍然无法工作

我不明白为什么要使用idproperty


看看下面的例子,你会发现一个简短的例子。您的代理读取器看起来应该类似,json也应该类似。使用root属性。

您何时要求计数?因为ajax调用是异步的,所以您可能在加载存储之前查询该值。
[{"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"}]
Ext.define('GoogleMarkerModel', {
    extend: 'Ext.data.Model',
    idProperty:'MainID',
    fields: ['ID','Locating','MainPower','Acc','PowerOff','Alarm','Speed','Direction','Latitude','Longitude','DateTime','MainID','IOState','OilState']
});

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',
        }

    }
});