Get repository value with column name - EXTJS 4

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://localhost/GPS/examples/tabs/get-googlemarker.php?mainid=1 

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
enter image description here

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

+4
source share
2 answers

as sra said you can set idProperty

 var MarkerStore = Ext.create('Ext.data.JsonStore', { model: 'GoogleMarkerModel', autoLoad: true, proxy: { type: 'ajax', url: 'get-googlemarker.php', baseParams: { mainid: 'value1' }, reader: { type: 'json', root: 'images', idProperty: 'MainId' } } }); 

then find the entry MarkerStore.getById(123) or 'MarkerStore.findRecord (' MainId ', 123)'

Important: It seems that extjs uses === operator instead of == to compare two variables. then if the variable is of type int, and the other is of type string, then the comparison may be false (for example, for "1" === 1). then you should use 'MarkerStore.findRecord (' MainId ',' 123 ')' instead.

+1
source

Some tips: JSON supports objects, arrays, strings, booleans, floats, but do you use only strings? In addition, the configuration of the automatic field so that all remain in rows. Further, you do not have idProperty defined for both your model and your reader. Based on your JSON string, I think this is an ID. You must add a line

 idProperty:'ID' 

model and reader and add the ID field to your model. If you do not want to use ID , I think it will be MainID , so insert this. Now, if you have idProperty, you can get a record for this id by calling store.getById(1234) .

You can also perform custom queries such as

 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'); } 

If this does not return anything, check to see if there is data in your store, and if so, provide more information about the storage settings that are being written.

+6
source

All Articles