表單提交

extjs表單的提交

//ExtJs 表單提交
form.getForm().submit({
success:function(){
},
failure:function(){
}
});
//ExtJs Ajax表單提交
form.form.doAction('submit', {
url : 'user.do?method=login',
method : 'post',
// 如果有表單以外的其它參數,可以加在這裏。我這裏暫時爲空,也可以將下面這句省略
params : '',
// 第一個參數是傳入該表單,第二個是Ext.form.Action對象用來取得服務器端傳過來的json數據
success : function(form, action) {
Ext.Msg.alert('操作', action.result.data); //result爲json對象
this.disabled = false;
},
failure : function(form, action) {
Ext.Msg.alert('警告', '用戶名或密碼錯誤!');
// 登錄失敗,將提交按鈕重新設爲可操作
this.disabled = false;
}
});


//ExtJs Ajax普通提交
Ext.Ajax.request({
url: 'login.do', //請求地址
//提交參數組
params: {
form.getForm().getValues() //取出表單所有值
},
//成功時回調
success: function(response, options) {
//獲取響應的json字符串
var responseArray = Ext.util.JSON.decode(response.responseText);
if(responseArray.success==true){
Ext.Msg.alert('恭喜','您已成功登錄!');
} else{
Ext.Msg.alert('失敗','登錄失敗,請重新登錄');
}
}
});

//老grid
var myData = ${jobs}; //二維數組
var store = new Ext.data.ArrayStore({
fields: [
{name: 'group'},
{name: 'name'},
{name: 'description'},
{name: 'jobClass'},
{name: 'namegroup'}
]
});
store.loadData(myData);
var grid = new Ext.grid.GridPanel({
title:"<fmt:message key='title.listAllJobs'/>",
store: store,
width:all_width,
autoHeight : true,
autoExpandColumn : 'namegroup',
viewConfig : {
forceFit : true
},
stripeRows: true,
columns: [
{header: "<fmt:message key='label.job.group'/>", width: 140, sortable: true, dataIndex: 'group'},
{header: "<fmt:message key='label.job.name'/>", width: 140, sortable: true, dataIndex: 'name'},
{header: "<fmt:message key='label.job.description'/>", width: 180, sortable: true, dataIndex: 'description'},
{header: "<fmt:message key='label.job.jobClass'/>", width: 200, sortable: true, dataIndex: 'jobClass'},
{id : 'namegroup',header: "<fmt:message key='label.global.actions'/>", dataIndex: 'namegroup', renderer: change}
],
bbar: new Ext.PagingToolbar({ afterPageText: '/ {0}',beforePageText: '頁',firstText: '第一頁'
,prevText: '前一頁',nextText: '後一頁',lastText: '最後一頁',refreshText: '刷新',store: store
, pageSize: 20,displayInfo: true, displayMsg: '顯示 {0} - {1} 條記錄,共 {2} 條', emptyMsg: "沒有數據"})
});

//如果store設置了url屬性,可重新指定url的參數:
store.load({params:{a:1, b:2}});

//如果store的內容只是普通的數組:
store.loadData([...]);

//如果store沒有單獨的變量定義,可以用
comboBox.initialConfig.store
//或
Ext.getCmp('comboId').initialConfig.store

//窗口
var win;

win = new Ext.Window({//添加/修改菜單彈出窗口
id:'winId',
title:'',
width: '',
height:'',
layout: 'fit',
modal:true,
closeAction:'hide',
buttonAlign:'center',
resizable:false,
items: [grid],
listeners:{
'hide':function(){}
}
});
Ext.getCmp('winId').show();

listeners:{
render:function(){},
click:function(a,e){}
}

//按鈕
var button = new Ext.Button({
text:'查詢',
listeners:{click:function(a,e){
}}
})

//表單
var form = new Ext.FormPanel({
id:'form',
width: '',
height:42,
labelWidth: '', //標籤寬度
layout:'column', //分列
style:'padding:4 4 2 4',
defaults:{layout:'form'}, //子項默認使用form樣式
colspan:2,
frame:true,
submit: function(){
this.getEl().dom.action = '${pageContext.request.contextPath}/layout.table?method=addData'; //連接到服務器的url地址
this.getEl().dom.method = 'post';
this.getEl().dom.submit();
},
items:[
{
columnWidth:.17,
items: [{
xtype:'label',
text:'',
emptyText:'',
allowBlank:false,
blankText:'',
regex:/^[A-Za-z0-9]+$/,
regexText:'',
maxLength:20,
maxLengthText:''
}]
},{
columnWidth:.04,
items: [button]
}]
});
//form.getForm().isValid()

//表格
var table = new Ext.Panel({
renderTo:'content',
layout:'table',
width:'',
border:false,
layoutConfig: {columns:2}, //劃分兩列
bodyStyle:'background:#dfe8f6;border: 1px solid #dfe8f6',
defaults: {frame:true}, //填充文本背景顏色
items:[form,chart,grid]
})

//標籤頁
var tabs = new Ext.TabPanel({
resizeTabs:true, // tab寬度自動調整
minTabWidth: 115, //tab最小寬度值
tabWidth:135, //tab初始寬度
enableTabScroll:true,//tab超出範圍出現橫向滾動條
frame:true,
activeTab:0,
defaults: {bodyStyle:'background:#dfe8f6;border: 1px solid #dfe8f6'},
items:[{
id:'tab1_1',
title:'',
items:[chart1] //添加table
},{
id:'tab1_2',
title:'',
items:[chart1]
}]
});

var tools = [{
id:'gear',
qtip :'爲表單分配權限',
handler: function(e, target, panel){
//獲得grid中所選的表單編號(即id值)
sRows = grid.getSelections('id_');
if(sRows==null)
{
Ext.Msg.show({
title:'提示',
msg: '<b>請選擇表單後再分配權限!</b>',
buttons: {ok:'確定'},
icon: Ext.MessageBox.INFO,
maxWidth :300,
minWidth :300,
closable:false,
defaultTextHeight :100
});
return;
}
}
}]

//框架面板
var border = new Ext.Panel({
layout:'border',
renderTo:'content',
width:'',
height:'',
items:[{
region:'north',
xtype:'panel',
margins: '4 4 2 4',
height:42,
bodyStyle:'background:#dfe8f6;border: 1px solid #dfe8f6',
items:[form]
},{
region:'west',
id:'west-panel',
width: '',
style:'padding:2 2 4 4',
collapsible: true,
defaults:{border:false},
layoutConfig:{
animate:true
},
items: [tree]
},{
region:'center',
style:'padding:2 4 4 2',
border:false,
items:[tabs]
}]
});

//日期控件
var dateSign_start = new Ext.form.DateField({
value:startTime,
format:"Y-m",
fieldLabel:'開始時間',
listeners:{
change:function(){
}
}
});

//下拉列表
//靜態
var fields=["name","valtext"];
var data_branchCompany=[['01','1月'],['02','2月']];
var store_branchCompany = new Ext.data.SimpleStore({
fields:fields,
data:data_month
});
//動態
var dsUrl_branchCompany ="${pageContext.request.contextPath}/adapter2Table.table?key=branchCompany&dropdownlist=true";
var store_branchCompany = new Ext.data.Store({
url:dsUrl_branchCompany,
autoLoad: true,
reader: new Ext.data.JsonReader({},[
//設置如何解析
{name:'name'},
{name:'valtext'}
])
,listeners:{
"load":function()
{
}
}
});
var comboBox_branchCompany = new Ext.form.ComboBox({
id:'comboBox_branchCompanyId',
width: 75,
selectOnFocus : true,
allowBlank:false,
readOnly:true,
emptyText: '',
fieldLabel:'',
store:store_branchCompany,
triggerAction: "all", //不加該語句選中某項後
mode: "local", //動態需要
displayField: "name",
valueField: "valtext",
listeners: {
"select": function (combo,record,index){
//record.get("name");
}
}
});

//隱藏div
type.on("select",function(combo,record,index){
if(record.get('valtext') == 0){
}
});


//樹
var tree = new Ext.tree.TreePanel({
id:'tree',
border: false,
containerScroll: true,
enableDD:false,//設置是否允許拖拽
useArrows: false,//是否使用箭頭記號,默認爲false
rootVisible :true,//設置是否顯示根節點
autoScroll:true,
loader: new Ext.tree.TreeLoader({
dataUrl: '${pageContext.request.contextPath}/treeQuery.tree?method=queryNode&key=product_order',
listeners:{beforeload:function(treeLoader, node) {
this.baseParams.id = node.id;
}}
}),
root: {
nodeType: 'async',
text: '付費節目',
draggable: false,
id: '1'
},
listeners:{
click:function(node,ev){
id=node.id;
}
}
});
tree.getRootNode().expand();

tree_org.on("append",function(tree,parentNode,node,index)
{
for(var i=0,len=roles.length;i<len;i++)
{
if(roles[i].編號 == node.id)
{
node.attributes.checked=true;
break;
}
}
});

//滑動菜單
{
region:'west',
id:'west-panel',
title:'West',
width: 200,
style:'padding:4 2 4 4',
collapsible: true,
layout:'accordion',
defaults:{border:false},
layoutConfig:{
animate:true
},
items: [{
title:'菜單1',
items:[tree]
},{
title:'菜單2',
contentEl:'hw'
}]
}

//表單中控件
{
fieldLabel: '性別',
xtype:'radiogroup',
items:[{
boxLabel:'男',
name: 'SEX_',
value:"${SEX_}",
checked:true,
inputValue: 1
},{
boxLabel:'女',
name: 'SEX_',
inputValue: 2
}]
},{
fieldLabel: 'SHOURU',
xtype:'checkboxgroup',
items:[{
boxLabel:'SHOURU1',
name: 'SHOURU',
checked:true,
inputValue: 1
},{
boxLabel:'SHOURU2',
name: 'SHOURU',
inputValue: 2
},{
boxLabel:'SHOURU3',
name: 'SHOURU',
inputValue: 3
}]
},{
xtype:'field',
inputType:'file',
name:'SHUISHOU',
fieldLabel:'上傳'
},{
xtype:'textfield',
name:"",
hidden:true,
hideMode:"display",
hideLabel:true,
value:""
},{
frame:false,border:false,baseCls:'x-plain',items:[{
xtype:'htmleditor',
id:'id_htmleditor',
width:500,
height:350,
name:'rulecontent_',
fieldLabel:'規則信息'
}]}

//Ext dom操作
Ext.getDom('')//返回Js對象
Ext.getCmp('').getValue();
Ext.getCmp("org-tree-panel").getChecked("id");//獲得樹節點
Ext.getCmp('form').form.findField("name").setValue('1',true);
Ext.getCmp('form').form.findField('name').getValue().inputValue;//radio選中值
grid.getSelections('列名');//獲得選中
//checkbox選中值
var checkbox = Ext.getCmp('form').form.findField('name');
if(checkbox.items.get(i).checked){
checkbox.items.get(i).inputValue;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章