4

私は次の店を持っています:

Ext.define('Sencha.model.MenuPoint', {
extend: 'Ext.data.Model',

config: {
    fields: [
        {name: 'id', type: 'string'},
        // this is id of the element, example child id, report id, and so fourth
        //{name: 'elementId', type: 'int'},
        {name: 'name', type: 'string'},
        {name: 'icon_url', type: 'string'},
        {name: 'xtype', type: 'string'}
    ]
}
});

そして、私は次のように値を挿入および取得することができます。

var keyValue = new Object();
keyValue.key = "adultId";
keyValue.value = adultObj.adultId;
console.log("keyValue: "+keyValue);
var sessionStore = Ext.getStore('MySessionStore');
sessionStore.add(keyValue);
sessionStore.sync();

var index = sessionStore.find('key',keyValue.key);
console.log("index: "+index);
var keyValue2 = sessionStore.getAt(index);
console.log("keyValue2: "+keyValue2);

しかし、最初にインデックスを取得してから値を取得するのは非常に面倒です。次のようなことはできません。

var value = store.get(key);

4

2 に答える 2

6

あなたは機能を使うことができます

var record = store.findRecord('id', key)

それはへの近道です

index = store.find('id', key);
record = index != -1 ? store.getAt(index) : null;

乾杯、オレグ

于 2012-07-29T20:26:31.200 に答える
0

使用する

store.findRecord('id', key, 0, false, true, true);

デフォルトでは、findRecord検索は正規表現を使用します。次のような表現を得るには、6つのパラメータすべてを渡す必要があります===

または、「id」で見つけた場合は、store.getById(key)

フィドルを見る

于 2016-05-11T08:21:57.077 に答える