[英]Retrieving the url parameter from a JSON store from a EXTJS ComboBox
[英]extJs pass parameter from combobox selection to store creation via proxy
我正在使用ExtJs6,當我在組合框中選擇一個項目時,我希望它使用代理來加載商店,並將參數從combobbox選擇中傳遞給代理。 我還想在登錄屏幕中包含用戶名和密碼。 (不知道如何保存該部分並重復使用)
到目前為止,我在組合框選擇上使用的方法如下。
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);
},
如何從中獲取參數... 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
});
最后,如何從登錄窗口傳遞用戶名和密碼。
我在這里選擇了組合框...
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);
}
});
我在這里創建視圖
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
]
});
您可以為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);
});
}
});
首先是-
1)每次選擇一個值都將創建一個商店。 請從選擇回調中刪除該商店創建代碼
2)從您的商店代理中,可見您正在將用戶名和密碼(???)作為參數傳遞給get調用。 請甚至不要考慮在那里使用密碼。 密碼只能輸入一種服務-登錄服務。 即使在那里,您也應該加密密碼。
現在回答您的問題-在您選擇的回調中,獲取對商店的引用,然后執行以下操作-
var store = [YOUR_STORE]; store.proxy.extraParams = { user: 'myUsername' pw: 'myPassword', cid: 'paramater from combobox selection' }; store.load(....);
或者,如果您只想設置cid,
store.proxy.extraParams.cid = '......'; store.load(........);
希望有幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.