亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Extjs4.0 ComboBox如何實現(xiàn)三級聯(lián)動

 更新時間:2016年05月11日 09:10:48   作者:yangxiaojun9238  
Extjs4.0 ComboBox如何實現(xiàn)三級聯(lián)動,許多網(wǎng)友都很好奇這個問題,明確的一點是在extjs4.0中要使用load來獲取數(shù)據(jù),到底如何實現(xiàn),下面小編為大家分享具體步驟

很多網(wǎng)友在問,Extjs4.0 ComboBox如何實現(xiàn),好在之前用3.x實現(xiàn)過一個三級聯(lián)動,如今用Extjs4.0來實現(xiàn)同樣的聯(lián)動效果。其中注意的一點就是,3.x中的model:'local'在Extjs4.0中用queryMode: 'local'來表示,而且在3.x中Load數(shù)據(jù)時用reload,但是在extjs4.0中要使用load來獲取數(shù)據(jù)。如下圖:

代碼部分

先看HTML代碼:

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MHZG.NET-城市三級聯(lián)動實例</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../bootstrap.js"></script>
<script type="text/javascript" src="../../locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="combobox.js"></script>
</head>

<body>
</body>
</html>

簡單的很,就是加載了基本的CSS文件和JS文件,并且加載自定義的combobox.js文件。

combobox.js:

 Ext.require('Ext.*');
Ext.onReady(function(){
 //定義ComboBox模型
 Ext.define('State', {
   extend: 'Ext.data.Model',
   fields: [
     {type: 'int', name: 'id'},
     {type: 'string', name: 'cname'}
   ]
 });
 
 //加載省數(shù)據(jù)源
 var store = Ext.create('Ext.data.Store', {
   model: 'State',
   proxy: {
     type: 'ajax',
     url: 'city.asp?act=sheng&n='+new Date().getTime()+''
   },
   autoLoad: true,
   remoteSort:true
 });
 //加載市數(shù)據(jù)源
 var store1 = Ext.create('Ext.data.Store', {
   model: 'State',
   proxy: {
     type: 'ajax',
     url: 'city.asp?act=shi&n='+new Date().getTime()+''
   },
   autoLoad: false,
   remoteSort:true
 });
 //加載區(qū)數(shù)據(jù)源
 var store2 = Ext.create('Ext.data.Store', {
   model: 'State',
   proxy: {
     type: 'ajax',
     url: 'city.asp?act=qu&n='+new Date().getTime()+''
   },
   autoLoad: false,
   remoteSort:true
 });
  
 
 
 Ext.create("Ext.panel.Panel",{
  renderTo: document.body,
  width:290,
  height:220,
  title:"城市三級聯(lián)動",
  plain: true,
  margin:'30 10 0 80',
  bodyStyle: "padding: 45px 15px 15px 15px;",
  defaults :{
    autoScroll: true,
    bodyPadding: 10
  },
  items:[{
    xtype:"combo",
    name:'sheng',
    id : 'sheng',
    fieldLabel:'選擇省',
    displayField:'cname',
    valueField:'id',
    store:store,
    triggerAction:'all',
    queryMode: 'local', 
    selectOnFocus:true,
    forceSelection: true,
    allowBlank:false,
    editable: true,
    emptyText:'請選擇省',
    blankText : '請選擇省',
    listeners:{  
      select:function(combo, record,index){
         try{
           //userAdd = record.data.name;
           var parent=Ext.getCmp('shi');
           var parent1 = Ext.getCmp("qu");
           parent.clearValue();
           parent1.clearValue();
           parent.store.load({params:{param:this.value}});
         }
         catch(ex){
           Ext.MessageBox.alert("錯誤","數(shù)據(jù)加載失敗。");
         }
      }
    }
    },
    {
    xtype:"combo",
    name:'shi',
    id : 'shi',
    fieldLabel:'選擇市',
    displayField:'cname',
    valueField:'id',
    store:store1,
    triggerAction:'all',
    queryMode: 'local',
    selectOnFocus:true,
    forceSelection: true,
    allowBlank:false,
    editable: true,
    emptyText:'請選擇市',
    blankText : '請選擇市',
    listeners:{  
      select:function(combo, record,index){
         try{
           //userAdd = record.data.name;
           var parent = Ext.getCmp("qu");
           parent.clearValue();
           parent.store.load({params:{param:this.value}});
         }
         catch(ex){
           Ext.MessageBox.alert("錯誤","數(shù)據(jù)加載失敗。");
         }
      }
    }
    },
    {
    xtype:"combo",
    name:'qu',
    id : 'qu',
    fieldLabel:'選擇區(qū)',
    displayField:'cname',
    valueField:'id',
    store:store2,
    triggerAction:'all',
    queryMode: 'local',
    selectOnFocus:true,
    forceSelection: true,
    allowBlank:false,
    editable: true,
    emptyText:'請選擇區(qū)',
    blankText : '請選擇區(qū)',
    }
  ]
 })
});

上述代碼中,如果在ComboBox直接定義store數(shù)據(jù)源,會出現(xiàn)這樣一種情況,那就是當選擇完第一個省,點擊第二個市的時候,會閃一下,再點擊,才會出現(xiàn)市的數(shù)據(jù)。那么要解決這樣的情況,那么必須先要定義好省、市、區(qū)的數(shù)據(jù)源。那么再點擊的時候,就不會出現(xiàn)上述情況了。

代碼中,使用store為省的數(shù)據(jù),設置其autoLoad為true,那么頁面第一次加載的時候,就會自動加載省的數(shù)據(jù),然后給省和市添加了監(jiān)聽select,作用在于當點擊省的時候,要清空市和區(qū)的數(shù)據(jù),并根據(jù)當前選定的值去加載對應的數(shù)據(jù)到市的數(shù)據(jù)源中。當然store1和store2原理是一樣的。

最后,服務端要根據(jù)傳的值進行數(shù)據(jù)檢索及返回正確數(shù)據(jù),這里沒有從數(shù)據(jù)庫中查詢數(shù)據(jù),而只是簡單的寫了一些測試代碼,相信extjs代碼沒有任何的問題了,那么服務端返回數(shù)據(jù),就不是一件很重要的事情了。

City.asp:

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
  Response.ContentType = "text/html"
  Response.Charset = "UTF-8"
%>
<%
  Dim act:act = Request("act")
  Dim param : param = Request("param")
  If act = "sheng" Then
    Response.Write("[")
    Response.Write("{""cname"":""北京市"",""id"":""110000""},")
    Response.Write("{""cname"":""內(nèi)蒙古自治區(qū)"",""id"":""150000""}")
    Response.Write("]")
  End If
  If act = "shi" Then
    If param = "110000" Then
      Response.Write("[")
      Response.Write("{""cname"":""市轄區(qū)"",""id"":""110100""},")
      Response.Write("{""cname"":""市轄縣"",""id"":""110200""}")
      Response.Write("]")
    ElseIf param = "150000" Then
      Response.Write("[")
      Response.Write("{""cname"":""呼和浩特市"",""id"":""150100""},")
      Response.Write("{""cname"":""包頭市"",""id"":""150200""}")
      Response.Write("]")
    End If
  End If
  If act = "qu" Then
    If param = "110100" Then
      Response.Write("[")
      Response.Write("{""cname"":""朝陽區(qū)"",""id"":""110101""},")
      Response.Write("{""cname"":""昌平區(qū)"",""id"":""110102""}")
      Response.Write("]")
    ElseIf param = "110200" Then
      Response.Write("[")
      Response.Write("{""cname"":""密云縣"",""id"":""110201""},")
      Response.Write("{""cname"":""房山縣"",""id"":""110202""}")
      Response.Write("]")
    ElseIf param = "150100" Then
      Response.Write("[")
      Response.Write("{""cname"":""回民區(qū)"",""id"":""150101""},")
      Response.Write("{""cname"":""新城區(qū)"",""id"":""150102""}")
      Response.Write("]")
    ElseIf param = "150200" Then
      Response.Write("[")
      Response.Write("{""cname"":""青山區(qū)"",""id"":""150201""},")
      Response.Write("{""cname"":""東河區(qū)"",""id"":""150202""}")
      Response.Write("]")
    End If
  End If
%>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。

相關文章

  • ExtJS 2.0實用簡明教程之應用ExtJS

    ExtJS 2.0實用簡明教程之應用ExtJS

    應用extjs需要在頁面中引入extjs的樣式及extjs庫文件
    2009-04-04
  • Extjs實現(xiàn)下拉菜單效果

    Extjs實現(xiàn)下拉菜單效果

    這篇文章主要為大家介紹了Extjs實現(xiàn)下拉樹的相關代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-04-04
  • Extjs中通過Tree加載右側(cè)TabPanel具體實現(xiàn)

    Extjs中通過Tree加載右側(cè)TabPanel具體實現(xiàn)

    用Extjs4.1來做界面,有關Extjs4.1資料在網(wǎng)上也相對來說較少,下面是具體的實現(xiàn)代碼1.左側(cè)的功能樹2.需要打開的對應的view,有類似需求的朋友可以參考下哈
    2013-05-05
  • Ext JS添加子組件的誤區(qū)探討

    Ext JS添加子組件的誤區(qū)探討

    多人都習慣在渲染子組件的時候?qū)ird渲染到容器內(nèi)的一個div里,為什么那么多人喜歡使用這種方式來添加子組件呢,下面為大家詳細介紹下
    2013-06-06
  • Extjs表單常見驗證小結(jié)

    Extjs表單常見驗證小結(jié)

    Extjs表單驗證包括空驗證、用vtype格式進行簡單的驗證、高級自定義密碼驗證、使用正則表達式驗證等等
    2014-03-03
  • Extjs學習筆記之四 工具欄和菜單

    Extjs學習筆記之四 工具欄和菜單

    本文介紹在桌面程序開發(fā)中很常用也很簡單的工具欄和菜單,但是在通常的web開發(fā)中,要實現(xiàn)好工具欄和菜單并非易事,然而extjs使我們能夠用類似桌面程序開發(fā)的方法來開發(fā)web的工具欄和菜單。
    2010-01-01
  • ExtJs使用IFrame的實現(xiàn)代碼

    ExtJs使用IFrame的實現(xiàn)代碼

    Iframe 有的時候還是須要的,比如在Tab中嵌入報表、嵌入其它系統(tǒng)的界面。下面代碼是項目中一段。希望對用ExtJS開發(fā)的兄弟做個參考。
    2010-03-03
  • Extjs根據(jù)條件設置表格某行背景色示例

    Extjs根據(jù)條件設置表格某行背景色示例

    這篇文章主要介紹了Extjs如何根據(jù)條件設置表格某行背景色,需要的朋友可以參考下
    2014-07-07
  • extjs 為某個事件設置攔截器

    extjs 為某個事件設置攔截器

    Ext.util.Observable有一個重要的功能,可以為某個事件設置攔截器,統(tǒng)一管理方法的處罰。使用capture()和releaseCapture()來實現(xiàn)這個功能。
    2010-01-01
  • 學習ExtJS Panel常用方法

    學習ExtJS Panel常用方法

    ExtJS Panel常用方法,需要的朋友可以參考下。
    2009-10-10

最新評論