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',
}
}
});
这段代码我用来调用 MarkerStore 并传递值为 1 的参数 mainid
MarkerStore.load({
params: { //here you can define params on 'per request' basis
mainid: 1,
}
})
当我使用网络浏览器获取-googlemarker.php 和 mainid=1 将返回这些值
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"}]
但我试图列出所有数据,不幸的是 JSON 存储为空,我怀疑数据未存储在 MarkerStore 中,下面的代码正在尝试列出数据,但在控制台 FireBug 上没有写任何内容。
MarkerStore.each( function (model) {
console.log( model.get('MainID') );
});
任何想法?