Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs - How to get value from the Store by id?

Tags:

store

extjs

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?

like image 808
Andrei Avatar asked Oct 05 '11 06:10

Andrei


1 Answers

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);
like image 145
nscrob Avatar answered Nov 19 '22 05:11

nscrob