【ExtJS4学习笔记03】Ajax远程访问数据源示例
摘要:【ExtJS4学习笔记03】Ajax远程访问数据源示例:远程数据源的组合框示例
三、【ExtJS4学习笔记】Ajax远程访问数据源示例
前端页面:
01.
<
HTML
>
02.
HEAD
>
03.
TITLE
>远程数据源的组合框示例</
04.
Meta
http-equiv
=
"Content-Type"
content
"text/html; charset=utf-8"
05.
linkrel
"stylesheet"
type
"text/css"
href
"extjs4/resources/css/ext-all.css"
/>
06.
script"text/javascript"
src
"extjs4/bootstrap.js"
></
script
07.
"extjs4/ext-lang-zh_CN.js"08.
"text/javascript"09.
Ext.onReady(function(){
10.
//创建数据模型
11.
Ext.regModel('BookInfo',{
12.
fields: [{name: 'bookName'}]
13.
});
14.
//定义组合框中显示的数据源
15.
var bookStore = Ext.create('Ext.data.Store',92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">16.
model : 'BookInfo',
17.
proxy: {
18.
type: 'ajax',//Ext.data.AjaxProxy
19.
url : 'bookSearchServer.jsp',
20.
reader: new Ext.data.ArrayReader({model : 'BookInfo'})
21.
}
22.
});
23.
//创建表单
24.
Ext.create('Ext.form.Panel',{
25.
title:'Ext.form.field.ComboBox远程数据源示例',92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">26.
frame : true,92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">27.
height:100,92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">28.
width:270,92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">29.
renderTo: Ext.getBody(),92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">30.
bodyPadding: 5,92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">31.
defaults:{//统一设置表单字段默认属性
32.
labelSeparator :':',//分隔符
33.
labelWidth : 70,//标签宽度
34.
width : 200,//字段宽度
35.
labelAlign : 'left'//标签对齐方式
36.
},92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">37.
items:[{
38.
xtype : 'combo',92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">39.
fieldLabel:'书籍列表',92)!important; margin:0px!important; border:0px!important; outline:0px!important; text-align:right!important; float:left!important; vertical-align:baseline!important; position:static!important; left:auto!important; top:auto!important; right:auto!important; bottom:auto!important; height:auto!important; width:3em!important; line-height:1.2em!important; font-size:13px!important; display:block!important; background:none!important">40.
listConfig : {
42.
emptyText : '未找到匹配值',//当值不在列表是的提示信息
43.
maxHeight : 100//设置下拉列表的最大高度为60像素
47.
queryDelay : 300,//查询延迟时间
48.
queryParam : 'searchbook',//查询的名字
49.
triggerAction: 'all',//单击触发按钮显示全部数据
50.
store : bookStore,//设置数据源
51.
displayField:'bookName',//定义要显示的字段
52.
valueField:'bookName',//定义值字段
53.
queryMode: 'remote'//远程模式
54.
}]
55.
56.
57.
</58.
59.
BODY
STYLE
"margin: 10px"
60.
BODY61.
>
JSP代码:
<%@ page language=
"java"
contentType=
pageEncoding=
"utf-8"
%>
<%
String bookName = request.getParameter(
"searchbook"
);
String jav =
"['java编程思想'],['java入门'],['javascript程序设计']"
;
String cpp =
"['c++编程思想'],['c++入门'],['c++程序设计']"
;
return
}
else
{
bookName = bookName.substring(0,3);
//取查询字符串的前3个字符
System.out.println(bookName);
"jav"
else
"c++"
"PHP"
"[['没有数据']]"
}
response.getWriter().write(books);
%>