Get the store value with column name - EXTJS 4 Get the store value with column name - EXTJS 4 json json

Get the store value with column name - EXTJS 4


Some hints: JSON supports objects, arrays, string, boolean, float but you are using just strings? In addition a auto field configuration so all would stay strings. Next is that you have no idProperty defined for neither your model nor your reader. Based on your JSON string I guess this is ID. You should add the line

idProperty:'ID'

to the model and the reader and add the field ID to your model. If you don't want to use ID I guess it would be MainID so insert that. Now if you have a idProperty you can get the record by it's id by calling store.getById(1234).

You can also do custom searches like this

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 returns nothing check if there is data in your store and if so supply more information how the store setups that record.


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 record by MarkerStore.getById(123) or 'MarkerStore.findRecord('MainId', 123)'

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