1

データストアで特定のレコードを検索するにはどうすればよいですか?find()とfindBy()を試しましたが、どちらも-1を返します。

var index = clientStore.find('ClientID', '37');

クライアントのリストが入ったコンボボックスがあります。私が欲しいのは、そのコンボにデフォルト値を設定できるようにすることです。setValueを使用して値を正しく設定し、setRawValueを使用して表示値を設定することもできますが、clientIDに基づいてデータストアにクエリを実行し、setRawValueで使用する会社名を取得できないようです。

それは理にかなっていますか?

以下の質問に対するデータストアコードは次のとおりです(申し訳ありませんが、そこに貼り付けることはできません)

var frmClientStore = new Ext.data.Store({
    id: 'frmClientStore',
    proxy: new Ext.data.HttpProxy({
        url: 'url here', 
        method: 'POST'
    }),
    reader: new Ext.data.JsonReader({
        root: 'rows',
        id: 'recordID'
    },[
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
      ])
});
4

2 に答える 2

3

構成にはいくつかの問題があります。まずid、読み取りの-propertyは-propertyである必要がありますidPropertyidストアの-propertyは-propertyである必要がありますstoreIdid非推奨)。そして、コードでfrmClientStore参照clientStoreしているときに変数が呼び出されます(タイプミスの可能性があります)。

var frmClientStore = new Ext.data.Store({
    storeId: 'frmClientStore',
    proxy: new Ext.data.HttpProxy({
        url: 'url here', 
        method: 'POST'
    }),
    reader: new Ext.data.JsonReader({
        root: 'rows',
        idProperty: 'recordID'
    },[
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
      ])
});

そして最後に:あなたがそこからレコードを取得しようとしたときにあなたの店はロードされましたか?

試す

frmClientStore.load({
    callback: function(rs) {
        console.log(rs);
        console.log(this.find('ClientID', '37'));
    }
});
于 2011-03-31T13:30:12.673 に答える
0

あなたがリストした方法は正しいはずです。ただし、フィールド名では大文字と小文字が区別されることを指摘しておく必要があります。数字(あなたが望むものかもしれない)の代わりに(あなたがリストしたように)文字列を検索している可能性もあります。

' ClientID'が正しいフィールド名であるとすると、次のことを試してください。

var index = clientStore.find('ClientID', 37);

編集

また、JsonReaderについて何かがおかしいことに気づきました。それはもっとこのようにすべきではありません:

//...
reader: new Ext.data.JsonReader({
    root: 'rows',
    id: 'recordID'
    fields: [ //list fields here as part of the JsonReader
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
    ]
})
于 2011-03-31T01:47:58.597 に答える