我使用ExtJs6,当我选择组合框中的项目时,我希望它使用代理加载商店,将参数从组合框选择传递给代理。我还想在登录屏幕中包含用户名和密码。 (不知道如何保存该部分并重复使用)
到目前为止,我在组合框选择中使用的方法如下:
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
});
最后,我如何从登录窗口传递用户名和密码。
我在这里选择了COMBOBOX ......
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
]
});
答案 0 :(得分:1)
您可以为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 :(得分:0)
首先要做的事情 -
1)每次选择值时,您都在创建商店。请从选择回调中取出商店创建代码
2)从您的商店代理,可见您将用户名和密码(???)作为参数传递给get调用。请不要考虑在那里使用密码。密码应仅输入一个服务 - 登录服务。即使你也应该加密密码。
现在回答你的问题 - 在您的选择回调中,获取对商店的引用,然后执行以下操作 -
gridApi.colResizable.on.columnSizeChanged($scope, function () {
const state = gridApi.saveState.save();
// {"columns":[...],"scrollFocus":{},"selection":[],"grouping":{},"treeView":{}}
gridApi.restore($scope, state);
});
或者如果您只想设置cid,
var store = [YOUR_STORE];
store.proxy.extraParams = {
user: 'myUsername'
pw: 'myPassword',
cid: 'paramater from combobox selection'
};
store.load(....);
希望有所帮助:)