11

How to get value from the Store by id?

store in such fields

    fields: [
    {name: "id", type: 'int'},
    {name: "name", type: 'String'},...

I need to get the id - name value.

I try so:

    var rec = Ext.StoreMgr.lookup("MyStore").getById(id);
    alert(rec.data.name);

what am I doing wrong?

Andrei
  • 1,125
  • 2
  • 15
  • 29

1 Answers1

24

The function getById finds the record with the specified id which has nothing to do to with the id you specified in the fields config - Basically you're looking at record.id while you should be looking at record.data.id.

For 3.3.1 you should use:

var index = Ext.StoreMgr.lookup("MyStore").findExact('id',id);
var rec = Ext.StoreMgr.lookup("MyStore").getAt(index);
Tom O.
  • 5,730
  • 2
  • 21
  • 35
nscrob
  • 4,483
  • 1
  • 20
  • 24