Ext.define('GoogleMarkerModel', { extend: 'Ext.data.Model', fields: ['Locating','MainPower','Acc','PowerOff','Alarm','Speed','Direction','Latitude','Longitude','DateTime','MainID', 'DeviceID','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', root: 'images' } } }); tree.on('checkchange', function(node){ var data = node.data; Ext.MessageBox.show({ title: 'Changed checkbox status', msg: 'MainID: ' + data.MainID + ' <br /> Checkbox status: ' + data.checked, icon: Ext.MessageBox.INFO }); if (data.checked == true){ MarkerStore.load({ params: { //here you can define params on 'per request' basis mainid: data.MainID, } }) var options = { lat:MarkerStore[0].Latitude, lng:MarkerStore[0].Longitude, marker: {title:"Hello World!"}, listeners: { click: function(e){ } } } addDoctorLocation(options); } })
And this is an example to get the return value
http:
return
[{"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"}]
This is the return value of get-googlemarker.php. I want to get the Latitude value in the lat variable and save the longitude in the longt variable. Something like that:
Find the row where MainID is 1, and get the Latitude of the column.
UPDATE 2
var lati,longi; var record = MarkerStore.findRecord('MainID',data.MainID); if(record) { lati = record.get('Latitude'); longi = record.get('Longitude'); }
Return record is zero, can not find MainID = 1? What for? data.MainID is 1.
UPDATE 3
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', } } });
I added idProperty, but still can't work.
Error

LAST CODE
tree.on('checkchange', function(node){ var data = node.data; if (data.checked == true){ MarkerStore.load({ params: { //here you can define params on 'per request' basis mainid: data.MainID, } }) var lati,longi; var recordPos = MarkerStore.findBy(function(rec,id){ return rec.data.MainID == data.MainID; }, this); if(recordPos > -1) { var record = MarkerStore.getAt(recordPos); lati = record.get('Latitude'); longi = record.get('Longitude'); } Ext.MessageBox.show({ title: 'Changed checkbox status', msg: 'MainID: ' + data.MainID + ' <br /> Checkbox status: ' + data.checked + ' <br /> lati: ' + lati + ' <br />', icon: Ext.MessageBox.INFO }); var options = { lat:lati, lng:longi, marker: {title:"Hello World!"}, listeners: { click: function(e){ } } } addDoctorLocation(options); } })
It is still impossible to get the lati value. Any idea?
How to make sure that MarkerStore has data inside? I think MarkerStore is empty. How to check it?
UPDATE 4
var lati,longi; var recordPos = MarkerStore.findRecord('MainID', '1'); lati = recordPos.get('Latitude'); longi = recordPos.get('Longitude');
still cannot work, recordPos is null. FIRE ERROR
TypeError: recordPos is null [Break On This Error] lati = recordPos.get('Latitude');
I think the problem in the JSON store is saving data from PHP
UPDATE 5
I am sure that the JSON repository has data, because I am trying to print all the JSON repository data using this code
MarkerStore.on('load', function(store, records) { for (var i = 0; i < records.length; i++) { console.log(records[i].get('Latitude')); }; });
and printing data on the console