第九讲:ExtJS组件之FormPanel(中)

ComboBox组合框。

示例一:显示本地数据。(相应的一定会有远程数据,教程一般都是模拟数据,事实上数据处理的能力一定要强

Ext.onReady(function(){

Ext.QuickTips.init();

 

var store = new Ext.data.SimpleStore({

fields:["city"],

data:[

["北京"],

["广州"],

["上海"]

]

});

 

var form = new Ext.FormPanel({

renderTo:"form",

title:"表单Panel",

width:300,

height:300,

frame:true,

labelSeparator:":",

labelWidth:30,

items:[

new Ext.form.ComboBox({

id:"city",

name:"city",

fieldLabel:"城市",

triggerAction:"all",//查询所有数据

store:store,

displayField:"city",

valueField:"city",

mode:"local"

})

]

});

});

 

示例二:键值对的设置。

Ext.onReady(function(){

Ext.QuickTips.init();

 

var store = new Ext.data.SimpleStore({

fields:["chinese","english"],

data:[

["北京","beijing"],

["广州","guangzhou"],

["上海","shanghai"]

]

});

 

var form = new Ext.FormPanel({

renderTo:"form",

title:"表单Panel",

width:300,

height:300,

frame:true,

labelSeparator:":",

labelWidth:30,

items:[

new Ext.form.ComboBox({

id:"city",

name:"city",

fieldLabel:"城市",

triggerAction:"all",//查询所有数据

store:store,

displayField:"chinese",

valueField:"english",

mode:"local"

})

]

});

});

 

示例三:获得value值。

Ext.onReady(function(){

Ext.QuickTips.init();

 

var store = new Ext.data.SimpleStore({

fields:["chinese","english"],

data:[

["北京","beijing"],

["广州","guangzhou"],

["上海","shanghai"]

]

});

 

var form = new Ext.FormPanel({

renderTo:"form",

title:"表单Panel",

width:300,

height:300,

frame:true,

labelSeparator:":",

labelWidth:30,

items:[

new Ext.form.ComboBox({

id:"city",

name:"city",

fieldLabel:"城市",

triggerAction:"all",//查询所有数据

store:store,

displayField:"chinese",

valueField:"english",

mode:"local",

hiddenName:"cityValue",

listeners:{

"select":function(){

Ext.MessageBox.alert("城市","你选择的城市是" +  Ext.get("cityValue").getValue())

}

}

})

]

});

});

 

示例四:获得远程数据。

Ext.onReady(function(){

Ext.QuickTips.init();

 

var store = new Ext.data.SimpleStore({

fields:["chinese","english"],

proxy: new Ext.data.HttpProxy({

url:"citySearchServer.jsp"

})

});

 

var form = new Ext.FormPanel({

renderTo:"form",

title:"表单Panel",

width:300,

height:300,

frame:true,

labelSeparator:":",

labelWidth:30,

items:[

new Ext.form.ComboBox({

id:"city",

name:"city",

fieldLabel:"城市",

triggerAction:"all",//查询所有数据

store:store,

displayField:"chinese",

valueField:"english",

mode:"remote",

hiddenName:"cityValue",

listeners:{

"select":function(){

Ext.MessageBox.alert("城市","你选择的城市是" +  Ext.get("cityValue").getValue())

}

}

})

]

});

});

 

<%@ page language="java" contentType="text/html; charset=gb2312"

pageEncoding="gb2312"%>

<%

String citys = "[['北京','beijing'],['上海','shanghai'],['广州','guangzhou'],['长沙','changsha']]";

response.getWriter().write(citys);

%>

示例五:动态查询。

Ext.onReady(function(){

Ext.QuickTips.init();

 

var store = new Ext.data.SimpleStore({

fields:["chinese","english"],

proxy: new Ext.data.HttpProxy({

url:"citySearchServer2.jsp"//现在一般都是前后端分离开发的,但是很久前都是不分离的

})

});

 

var form = new Ext.FormPanel({

renderTo:"form",

title:"表单Panel",

width:300,

height:300,

frame:true,

labelSeparator:":",

labelWidth:30,

items:[

new Ext.form.ComboBox({

id:"city",

name:"city",

fieldLabel:"城市",

triggerAction:"all",//查询所有数据

store:store,

displayField:"chinese",

valueField:"english",

mode:"remote",

hiddenName:"cityValue",

queryParam:"shengfen",//查询参数

allQuery:"hunan",//查询值

listeners:{

"select":function(){

Ext.MessageBox.alert("城市","你选择的城市是" +  Ext.get("cityValue").getValue())

}

}

})

]

});

});

 

<%@ page language="java" contentType="text/html; charset=gb2312"

pageEncoding="gb2312"%>

<%

String shengfen = request.getParameter("shengfen");

 

String beijing = "['北京','beijing']";

String guangdong = "['广州','guangzhou'],['中山','zhongshan']";

String hunan = "['长沙','changsha'],['益阳','yiyang']";

 

String citys = "";

if(shengfen.equals("beijing")) {

citys = "[" + beijing + "]";

} else if(shengfen.equals("guangdong")) {

citys = "[" + guangdong + "]";

} else if(shengfen.equals("hunan")) {

citys = "[" + hunan + "]";

}

response.getWriter().write(citys);

%>

示例六:ComboBox级联

Ext.onReady(function(){

Ext.QuickTips.init();

 

var store = new Ext.data.SimpleStore({

fields:["chinese","english"],

proxy: new Ext.data.HttpProxy({

url:"citySearchServer2.jsp"

})

});

 

var shenfenstore = new Ext.data.SimpleStore({

fields:["chinese","english"],

proxy: new Ext.data.HttpProxy({

url:"shengfenSearchServer.jsp"

})

})

 

var shengfen = new Ext.form.ComboBox({

id:"shengfen",

fieldLabel:"省份",

triggerAction:"all",//查询所有数据

displayField:"chinese",

valueField:"english",

mode:"remote",

hiddenName:"shengfenValue",

store:shenfenstore,

listeners:{

                  "select":function(combo, record,index){

                   city.clearValue();

                   store.proxy = new Ext.data.HttpProxy({

url:"citySearchServer2.jsp?shengfen=" + Ext.get("shengfenValue").getValue()

});

store.load();

                 }

           }

})

 

 

var city = new Ext.form.ComboBox({

id:"city",

name:"city",

fieldLabel:"城市",

triggerAction:"all",//查询所有数据

store:store,

displayField:"chinese",

valueField:"english",

mode:"remote",

hiddenName:"cityValue",

queryParam:"shengfen",//查询参数

allQuery:"hunan",//查询值

listeners:{

"select":function(){

Ext.MessageBox.alert("城市","你选择的城市是" +  Ext.get("cityValue").getValue())

}

}

})

 

var form = new Ext.FormPanel({

renderTo:"form",

title:"表单Panel",

width:300,

height:300,

frame:true,

labelSeparator:":",

labelWidth:30,

items:[

shengfen,city

]

});

});

forceSelection : true, 要求输入值必须在列表中存在

resizable : true,  允许改变下拉列表的大小

typeAhead : true,  允许自动选择匹配的剩余部分文本

value:'beijing',  默认选择北京

emptyText:'请选择一个城市//为空时显示文本

转换select组件为Ext.form.ComboBox的示例

Ext.onReady(function(){

var form = new Ext.form.FormPanel({

title:'转换select组件为Ext.form.ComboBox的示例',

labelSeparator :':',//分隔符

labelWidth : 80,//标签宽度

bodyStyle:'padding:5 5 5 5',//表单边距

frame : true,

height:80,

width:270,

applyTo :'form',

items:[

new Ext.form.ComboBox({

name:'level',

fieldLabel:'职称等级',

lazyRender : true,

triggerAction: 'all',//单击触发按钮显示全部数据

transform : 'levelName'

})

]

})

});

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head>

    <title>TestFormPanel</title>

    <script type="text/javascript" src="../Ext/adapter/ext/ext-base.js"></script>

    <script type="text/javascript" src="../Ext/ext-all-debug.js"></script>

    <script type="text/javascript" src="TestFormPanel3.js"></script>

    <link rel="stylesheet" type="text/css" href="../Ext/resources/css/ext-all.css"></link>

  <style type="text/css">

  </style>

  </head>

  <body>

<SELECT ID="levelName">

<OPTION VALUE="1">高级工程师</OPTION>

<OPTION VALUE="2">中级工程师</OPTION>

<OPTION VALUE="3" SELECTED>初级工程师</OPTION>

<OPTION VALUE="4">高级经济师</OPTION>

<OPTION VALUE="5">中级经济师</OPTION>

<OPTION VALUE="6">初级经济师</OPTION>

</SELECT>

  </body>

</html>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值