0

JSONP プロキシを使用してデータ ストアから接続されたオプションを持つ 2 つの選択フィールドがあります。最初の選択フィールドで選択した値に基づいて、2 番目の選択フィールドの値を変更する必要があります。このためには、selectfield で選択された値に基づいて、プロキシ extraParams のパラメータを変更する必要があると思います。

この投稿から .getProxy() メソッドを試しました ストアのパラメーターを変更/追加するにはどうすればよいですか?しかし、うまくいきません。コンソールにエラーがあります:

Uncaught TypeError: Object function () {
                    return this.constructor.apply(this, arguments);
                } has no method 'getProxy'

以下のコードと説明を参照してください。それを行う方法はありますか?

モデル:

Ext.define('Providers.model.Provider', {    
extend: 'Ext.data.Model',    
config: {       
   fields: [
        {
            name: 'id',
            type: 'int'
        }, 
        {
            name: 'name',
            type: 'string'
        }
    ]
}
});

1号店:

Ext.define('Providers.store.ProvidersType', {    
extend: 'Ext.data.Store',
config: {
    model: 'Providers.model.Provider',
    proxy: {
        type: 'scripttag',
        url : 'http://example.com/providers/service.php',
        extraParams: {
            action: 'provider_types',
            username: 'test2',
            callback: '?',                      
            format: 'json'          
        },          
        reader: {
            type: 'json',
            rootProperty: 'providers'
        }
    },      
    autoLoad: true
}
});

2店舗目:

Ext.define('Providers.store.Countries', {    
extend: 'Ext.data.Store',
config: {
    model: 'Providers.model.Provider',
    proxy: {
        type: 'scripttag',
        url : 'http://example.com/providers/service.php',
        extraParams: {
            action: 'countries',
            username: 'test2',
            provider_type: 14, //<--- here should be value from first selectfield
            callback: '?',                      
            format: 'json'          
        },          
        reader: {
            type: 'json',
            rootProperty: 'countries'
        },          
    },
    autoLoad: true      
}
});

レイアウト:

xtype: 'fieldset',
layout: 'vbox',                     
items: [                        
    {
        xtype: 'selectfield',
        id: 'selectType',           
        cls: 'combobox',
        store: 'ProvidersType',
        displayField: 'name',
        valueField: 'id',                           
        listeners: {
            change: function(field, value) {                                    
                if (value instanceof Ext.data.Model) {
                    value = value.get(field.getValueField());
                }
                console.log(value); //<-- get value works fine, how insert it in proxy param? 
                //Providers.store.Countries.getProxy().extraParams.provider_type = 10; <-- Do not work

            }
        }                           
    },                          
    {
        xtype: 'selectfield',   
        id: 'selectCountry',
        placeHolder: 'Country',
        cls: 'combobox',                        
        store: 'Countries',
        displayField: 'name',
        valueField: 'id'                            
    }

]

ありがとう。

4

1 に答える 1

2

新しいストア インスタンスを作成し、そのプロキシを設定してから、選択フィールドのストアをリセットできます。このコードをリスナー関数に追加できます。

newstore = Ext.create('Providers.store.Countries', {});
newstore.setProxy(
    {
        type: 'scripttag',
        url : 'http://example.com/providers/service.php',
        extraParams: {
            action: 'countries',
            username: 'test2',
            provider_type: value,
            callback: '?',                      
            format: 'json'          
        },          
        reader: {
            type: 'json',
            rootProperty: 'countries'
        },          
    }
);
newstore.load();

countrySelection = Ext.getCmp('selectCountry');
countrySelection.setStore(newstore); 
//OR: countrySelection.store = newstore;
于 2012-05-03T22:30:39.603 に答える