当前位置: 代码迷 >> Ajax >> 求Ext下拉框queryParam属性如何用
  详细解决方案

求Ext下拉框queryParam属性如何用

热度:771   发布时间:2012-02-07 17:45:36.0
求Ext下拉框queryParam属性怎么用 - Web 开发 / Ajax
用Ext想做一个类似于百度搜索的输入自动补全。。
别人告诉我用combobox 用queryParam  
求教怎么用。。。。
给份示例代码也成。。。

------解决方案--------------------
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script>
var oForm;
var ds = new Ext.data.Store({
    autoLoad:false,
    proxy:new Ext.data.HttpProxy({url:'test.asp',method:'GET'}),
    reader:new Ext.data.JsonReader({root:'data',id:'id'},[{name:'id',mapping:'id'},{name:'name',mapping:'name'}])
});
Ext.onReady(function(){
    Ext.QuickTips.init();
    oForm    = new Ext.FormPanel({
        renderTo:"form_panel",
        layout:"form",
        hideLabels:false,
        border:false,
        labelAlign:"right",
        labelWidth:70,
        items:[
            {fieldLabel:'输入',id:'sel_xxx',name:'sel_xxx',minChars:1,typeAhead:true,lastQuery:'',displayField:'name',valueField:'id',xtype:'combo',store:ds,editable:true,hiddenName:'xxx',forceSelection:true,mode:'remote',triggerAction:'all',
                listeners:{
                    beforequery:function(qe){
                        qe.query = escape(qe.query); // 这里escape用于中文,服务器端要Unescape
                    }
                }
            }
        ]
    });
});
</script>
<div id="form_panel"></div>

------解决方案--------------------
Ext.onReady(function(){
var n = 0;
var ds = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({url : 'userServlet'}),
reader : new Ext.data.JsonReader({
root:'userList'
}, [
{name : 'name',mapping:'name'},
{name : 'email',mapping:'email'}
])
});
var resultTpl = new Ext.XTemplate(
'<tpl for="."><div class="search-item">',
'<h3><span>{name}</h3>',
'{excerpt}',
'</div></tpl>'
);
var simple = new Ext.FormPanel({
labelWidth : 80,
title:'发送邮件',
defaultType : "textfield",
width : 800,
fileUpload : true,
defaults : {
width : 700
},
items :[{
xtype:'combo',
id : 'com',
triggerAction : "all",
mode:'remote',
store: ds,
displayField:'name',
valueField : 'email',
fieldLabel: '发送人',
tpl: resultTpl,
itemSelector: 'div.search-item',
queryParam : 'XXXXX',//用于后台接收
minChars : 2, //两个字符开始查询
typeAhead : true, 
typeAheadDelay : 500 //延时查询字符
}]
});
simple.render("show");
});

后台
String email = request.getParameter("XXXXX");
就能得到你输入的值
你再根据这个值进行模糊查询
  相关解决方案