2011-10-05 59 views
10

如何从商店获得价值IDExtJs - 如何通过id从商店中获取价值?

店等领域

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

我需要得到ID - 值。

我试试这样:

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

我究竟做错了什么?

回答

18

getById函数找到指定id的记录,这个记录与你在config字段中指定的id无关。基本上他在record.id中查找,你的查找在record.data.id中。

对于3.3.1你应该使用:

var index = Ext.StoreMgr.lookup("MyStore").findExact('id',id); 
var rec = Ext.StoreMgr.lookup("MyStore").getAt(index); 
+0

非常感谢你:) – Andrei