Ext.form.formPanel 與服務(wù)器交互 初始化表單
formPanel 初始化表單有兩種方式加載,一種是本地加載,一種是通過返回回來的Json格式數(shù)據(jù)加載到表單里面。 遠程加載是通過 form.getForm().load()加載。 var empReader = new Ext.data.JsonReader //解析Json格式數(shù)據(jù)。 ({ name:"empNo ", //表單對應(yīng)的屬性名 mapping:"empNo" //為json數(shù)據(jù)里面 對應(yīng)的屬性值 },{name:"empName", mapping:"empName"});
// 從后臺加載json格式數(shù)據(jù) //json數(shù)據(jù),即action中 selectByPrimaryEmployee 所要返回到頁面的json數(shù)據(jù)格式 var json = [{empNo:"111",empName:"小王"}]; printwrite.print(json); //將數(shù)據(jù)返回到前臺 這樣子就是通過將服務(wù)器數(shù)據(jù)加載到表單顯示。一定要注意,加載本地和加載遠程不要用錯方法了,加載遠程是用load(),里面?zhèn)鞯膗rl。 本地用 加載用loadRecord(),直接傳入一個Stroe的記錄集,就可以加載進去。 ------------------------------------------------------------------------------------------------------------------------------------ grid.on('rowdblclick', function(grid, rowIndex, e) {
Ext.form.Form.loadRecord( Record record ) 加載一條記錄,如果再做一點簡單的工作,form可以根據(jù)grid記錄的結(jié)構(gòu)自動生成、渲染。
baseCls : 'x-plain', labelWidth : 75, url : 'editCustomer.adminService', defaultType : 'textfield', items : [new Ext.form.TextField( { fieldLabel : 'userID', allowBlank : false, name : 'id', anchor : '90%' }), { fieldLabel : '用戶名', name : 'name', allowBlank : false,// readOnly:true, anchor : '90%' }, { fieldLabel : '真實姓名', name : 'realName', allowBlank : false, anchor : '90%' }, { fieldLabel : '國籍', name : 'unation', allowBlank : false, anchor : '90%' }] }); var editWin; var editCustomer = function() { if (!currRecord) { Ext.MessageBox.alert('提示', '請選擇一個用戶。'); } else { if (!editWin) { editWin = new Ext.Window( { title : '修改用戶信息', layout : 'fit', width : 500, height : 300, closeAction : 'hide', plain : true, modal : true, items : editForm, buttons : [ { text : '保存', handler : function() { // 保存修改信息 if (editForm.form.isValid()) { editForm.form.submit( { waitMsg : '正在處理...', failure : function(form, action) { Ext.MessageBox.alert( 'Error Message', '保存失敗'); }, success : function(form, action) { Ext.MessageBox.alert('提示', '保存成功'); addWin.hide(); store.reload(); } }); } else { Ext.MessageBox .alert('錯誤', '請修正頁面提示的錯誤后提交。'); } } }, { text : '關(guān)閉', handler : function() { editWin.hide(); } }] }); } editWin.show(); editForm.getForm().loadRecord(currRecord); } } |
|
來自: 喜氣蜘蛛 > 《JavaScript》