0
我在窗口中有商店,網格,窗口和幾個文本框。我需要的是,單擊網格中的動作列時,我需要獲取單擊行的rowIndex並將其作爲參數傳遞給窗口。在那裏,我需要加載商店並獲取值並將其設置在適當的文本框中。我不知道如何通過單擊將網格中的rowIndex傳遞給窗口。溫我試着提醒a
在testfunction
的值,它出現爲undefined
。請幫助和下面是我的代碼。將rowIndex傳遞給extjs中的窗口4
JS文件:當執行pass
Ext.onReady(function() {
var rIx;
Ext.create('Ext.data.Store', {
storeId:'employeeStore',
fields:['firstname', 'lastname', 'senority', 'dep', 'hired'],
data:[
{firstname:"Michael", lastname:"Scott", senority:7, dep:"Manangement", hired:"01/10/2004"},
{firstname:"Dwight", lastname:"Schrute", senority:2, dep:"Sales", hired:"04/01/2004"},
{firstname:"Jim", lastname:"Halpert", senority:3, dep:"Sales", hired:"02/22/2006"},
{firstname:"Kevin", lastname:"Malone", senority:4, dep:"Accounting", hired:"06/10/2007"},
{firstname:"Angela", lastname:"Martin", senority:5, dep:"Accounting", hired:"10/21/2008"}
]
});
Ext.create('Ext.grid.Panel', {
title: 'Employee Data',
store: Ext.data.StoreManager.lookup('employeeStore'),
columns: [
{ text: 'First Name', dataIndex: 'firstname' },
{
header: 'Button',
xtype: 'actioncolumn',
icon : 'test.png',
handler: function(grid, rowIndex, colIndex, item, e , record) {
rIx=rowIndex;
//var rec = grid.getStore().getAt(rowIndex);
//alert("Edit " + rec.get('firstname'));
Ext.create('MyWindow').show();
}
}
],
width: 500,
renderTo: Ext.getBody()
});
var testFunction = function(a){alert("a= "+a);
var r = Ext.data.StoreManager.lookup('employeeStore').getAt(a);
var firstname = r.get('firstname');
Ext.getCmp('fname').setValue(firstname);
};
Ext.define('MyWindow', {
extend: 'Ext.window.Window',
store : Ext.data.StoreManager.lookup('employeeStore'),
height: 250,
width: 250,
title: 'My Window',
items: [
{
xtype: 'textfield',
id : 'fname',
fieldLabel:'Name'
}
],
listeners: {
afterrender: Ext.Function.pass(testFunction, [rIx])
}
});
});
你好Wantok,你指出了我所做的錯誤以及正確的程序。非常感謝。我確實需要2個說明:1)使用的「win」是預定義的。 2)正如我所假設的,'win'將代表一個窗口,如果我想將rowIndex傳遞給面板,我應該指定什麼...... – CARTIC
「afterrender」事件處理程序的第一個參數是剛剛呈現的東西,在這種情況下是窗口。如果你願意,可以叫它'cmp'。它只是渲染的組件。您可以用相同的方式將rIx屬性添加到您喜歡的任何組件。 – wantok
非常感謝。這幾乎清除了我的疑惑。 – CARTIC