简体   繁体   English

extJs将参数从组合框选择传递到通过代理存储创建

[英]extJs pass parameter from combobox selection to store creation via proxy

I'm using ExtJs6, when I select an item in a combobox I want it to load a store using a proxy, passing a parameter from combobbox selection to the proxy. 我正在使用ExtJs6,当我在组合框中选择一个项目时,我希望它使用代理来加载商店,并将参数从combobbox选择中传递给代理。 I also want to include the username and password from the login screen. 我还想在登录屏幕中包含用户名和密码。 (don't know how to save that part and reuse) (不知道如何保存该部分并重复使用)

So far the method I use on combobox selection is as follows. 到目前为止,我在组合框选择上使用的方法如下。

    onComboboxSelect: function (combo, record, eOpts) {

    console.log('new listener was hit');
    //console.log(combo);
    //console.log(record);
    //console.log(eOpts);
    //debugger;

    //return selected Item
    var selectedValue = record.get('ClientName');
    var selectedCID = record.get('ClientID');

    //return clientId from store
    //var storeClients = Ext.data.StoreManager.lookup('myClientListStoreID');
    //var targetRecord = storeClients.findRecord('ClientName', selectedValue);

    var newStore = Ext.create('ExtApplication1.store.PositionsStore');
    console.log(newStore);
    newStore.load({
        callback: function (records) {
            Ext.each(records, function (record) {
                console.log(record);
            });
        }
    });
    console.log(newStore);

    //load positions store???
    //var x1 = Ext.data.StoreManager.lookup('myStore');
    //var x2 = Ext.data.StoreManager;
    //console.log(x1);
},

How can I take a parameter from that... SELECTEDCID, and pass to the store creation below 如何从中获取参数... SELECTEDCID,并传递给下面的商店创建

var encodedFilename = Ext.urlEncode({
user: 'myUsername',
pw: 'myPassword',
cid: 'paramater from combobox selection'
});

Ext.define('ExtApplication1.store.PositionsStore', {
extend: 'Ext.data.Store',

model: 'ExtApplication1.model.PositionsModel',

storeId: 'myStore',

alias: 'store.positionsstore',

proxy: {

    type: 'ajax',
    url: 'http://localhost:51020/Service4.svc/DownloadPos?' + encodedFilename,

    reader: {
        type: 'json',
        rootProperty: 'data'
    }

},

autoLoad: false

}); });

lastly, how can I pass the username and password from my login window as well. 最后,如何从登录窗口传递用户名和密码。

I EDITED COMBOBOX SELECT HERE...... 我在这里选择了组合框...

    onComboboxSelect: function (combo, record, eOpts) {

    console.log('new listener was hit');
    //console.log(combo);
    //console.log(record);
    //console.log(eOpts);
    //debugger;

    //return selected Item
    var selectedValue = record.get('ClientName');
    var selectedCID = record.get('ClientID');


    //return clientId from store
    //var storeClients = Ext.data.StoreManager.lookup        
('myClientListStoreID');
    //var targetRecord = storeClients.findRecord('ClientName',  
selectedValue);


    //find the grid that was created
    var mainPortalView = Ext.getCmp('mainportalID');
    var targetGrid = mainPortalView.down('grid');

    //find the store associated with that grid
    var targetStore = targetGrid.getStore();
    console.log(targetStore);
    //debugger

    //load and add items to the store

    //targetStore.proxy.extraParams = {
    //    user: 'stephen',
    //    pw: 'forero',
    //    cid: selectedCID
    //};

    targetStore.load({
        params: {
            user: 'stephen',
            pw: 'forero',
            cid: selectedCID
        },
        callback: function (records) {
            Ext.each(records, function (record) {
                console.log(record);
            });

            console.log(targetStore);

            //var targetStore2 = targetGrid.getStore();
            //console.log(targetStore2);
        }
    });

I CREATE THE VIEW WITH GRID HERE 我在这里创建视图

var myStore = Ext.create('ExtApplication1.store.PositionsStore');

var gridSummary = Ext.create('Ext.grid.Panel', {
    store: myStore,
    width: 600,
    title: 'my first grid',
    columns: [
        {
            text: 'AcctNum',
            dataIndex: 'AcctNum',
            width: 100
        },
        {
            text: 'AcctShortCode',
            dataIndex: 'AcctShortCode',
            flex: 1
        },
        {
            text: 'Exchange',
            dataIndex: 'Exchange',
            width: 200
        }
    ]
});



Ext.define('ExtApplication1.view.main.MainPortal', {
    extend: 'Ext.panel.Panel',

    xtype: 'mainportal',

    alias: 'widget.mainportal',

    id: 'mainportalID',

    html: 'user... this is the main portal window',

    autoScroll: true,

    bodyPadding: 10,

    items: [
        gridSummary
    ]

});

You can pass params for store.load method. 您可以为store.load方法传递参数。

newStore.load({
    params: {
        user: 'myUsername',
        pw: 'myPassword',
        cid: 'paramater from combobox selection'
    },
    callback: function (records) {
        Ext.each(records, function (record) {
            console.log(record);
        });
    }
});

First things first - 首先是-

1) You are creating a store everytime a value is selected. 1)每次选择一个值都将创建一个商店。 Please take that store creation code out of the select callback 请从选择回调中删除该商店创建代码

2) From your store proxy, its visible that you are passing username and password(???) as parameters to a get call. 2)从您的商店代理中,可见您正在将用户名和密码(???)作为参数传递给get调用。 Please don't even think about using the password there. 请甚至不要考虑在那里使用密码。 The password should be input to only one service - the login service. 密码只能输入一种服务-登录服务。 Even there also you should encrypt the password. 即使在那里,您也应该加密密码。

Now to answer your question - In your select callback, get a reference to the store and then do the following - 现在回答您的问题-在您选择的回调中,获取对商店的引用,然后执行以下操作-

var store = [YOUR_STORE]; store.proxy.extraParams = { user: 'myUsername' pw: 'myPassword', cid: 'paramater from combobox selection' }; store.load(....);

or if you only want to set the cid, 或者,如果您只想设置cid,

store.proxy.extraParams.cid = '......'; store.load(........);

Hope that helps :) 希望有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM