[英]can't load data from Grid to new Window with Form Extjs 4
我在將數據從網格加載到Extjs 4中的表單時遇到問題。
我試圖將字段vid發送到表單,僅用於測試,但我什至不能這樣做。 找到了很多例子,嘗試了這些想法。 做不到。
數據來自mongodb。
我可以完美地在網格中顯示它。
現在,我想單擊“編輯”按鈕以打開帶有表單的窗口並顯示信息。
我想念什么?
Ext.define('DevJS.view.users.List', {
extend: 'Ext.grid.Panel',
autoHeight: true,
forceFit: true,
this.columns = [
{text: 'Id', dataIndex: '_id', hidden: true},
{
text: 'Vid',
dataIndex: 'vid',
autoSizeColumn: true
}
...
xtype: 'actioncolumn',
autoSizeColumn: true,
items: [
{
iconCls: 'button-edit',
tooltip: 'Edit',
handler: function (grid, rowIndex, colIndex) {
this.up('grid').fireEvent('editRow', grid, rowIndex, colIndex);
}
},
{
iconCls: 'button-info',
itemId: 'Comments',
text: 'Comments',
handler: function (grid, rowIndex, item) {
alert(rowIndex)
win.record = rowIndex;
win.show()
}
}
]
}
];
//parent
this.callParent(arguments);
}
});
var form = new Ext.form.FormPanel({
title : 'Test form',
id:'form',
width : 300,
items : [{
xtype: 'textfield',
editable:false,
fieldLabel: 'vid',
name: 'vid'
}]
});
var win = new Ext.Window({
title : 'test',
items : [{
xtype : 'panel',
layout : 'column',
items : [form]
}],
listeners:{
afterrender:function(window) {
if(window.record) window.down('form').loadRecord(window.record);
}
}
});
只需在render方法之后嘗試一下即可:
if(window.record) window.down('form').getForm().loadRecord(window.record);
希望它能工作。
創建窗口時,將渲染該窗口(DOM在背景中的某個位置生成),但尚未設置window.record
。
但是在處理程序設置win.record
,不重新渲染窗口,僅顯示該窗口。
因此,如果您從afterrender
切換到beforeshow
事件,則該方法應該起作用,該事件在每次調用win.show()
時執行。
此外, window.record
包含記錄的索引,而不是記錄本身。 但是loadRecord
需要一條記錄,而不是索引。 嘗試像win.record = grid.getStore().getAt(rowIndex);
和loadRecord`應該能夠加載記錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.