国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Extjs讓combobox寫起來簡潔又漂亮

2019-11-19 18:08:03
字體:
供稿:網(wǎng)友

也已經(jīng)寫了很久時(shí)間的extjs ,每次都用到很多的combobox,配置很多東西覺得實(shí)在是太麻煩,所以根據(jù)常用到的情況寫了一個(gè)簡便的combobox,再次記錄下來,以免放在某個(gè)地方忘記了找不到了。

定義一個(gè)基本的baseCombobox類,如下。

Ext.define('Admin.view.baseCmp.BaseCombobox', { extend: 'Ext.form.field.ComboBox', xtype: 'baseCombobox', editable: false, labelSeparator: ':', labelWdith: 0, triggerAction: 'all', labelAlign: 'right', //forceSelection: true,此屬性操作時(shí),就算去掉文字后,失去焦點(diǎn)后還是會(huì)選擇上一次選擇的記錄 autoSelect: true, selectOnfocus: true, valueNotFoundText: '', name:'', queryMode: 'local', url:'', displayField: '', valueField: '', requires:['Admin.view.baseCmp.BaseComboboxController'], controller: 'baseComboboxController', emptyIndex:-1,//自定義屬性,空值所在下標(biāo),-1則不添加 selectIndex:0,//自定義屬性,自動(dòng)選擇下標(biāo) params:null,//自定義屬性,數(shù)據(jù)參數(shù) listeners: {  render: 'getComboData',  scope: 'controller' },});

Ext.define('Admin.view.baseCmp.BaseComboboxController', { extend: 'Ext.app.ViewController', alias: 'controller.baseComboboxController', getComboData: function (combo) {  Ext.Ajax.request({   url: combo.url,   method :'POST',   params:combo.params,   success: function (response) {    var dataJson = Ext.decode(response.responseText);    if(dataJson.state != 200 || dataJson.data == null || dataJson.data.length == 0)    {     //服務(wù)器返回錯(cuò)誤     return ;    }    var data = dataJson.data;    //插入“全部”選項(xiàng)    if(combo.emptyIndex >= 0)    {     var emp = {};     emp[combo.displayField] = "全部";     emp[combo.valueField] = "全部";     Ext.Array.insert(data,combo.emptyIndex,[emp]);    }    var store = Ext.create('Ext.data.Store', {     fields: Ext.Object.getKeys(data[0]),     data: data    });    combo.setStore(store);    //如果指定選中某個(gè)值    if(combo.selectValue != null)    {     combo.select(combo.selectValue);    }    else    {     //如果指定選中某個(gè)下標(biāo)的值,-1為最后一個(gè),> 0 則為第selectIndex個(gè)     if(combo.selectIndex == -1)     {      console.log(data.length - 1);      combo.select(data[data.length - 1][combo.valueField]);     }     else     {      combo.select(data[combo.selectIndex][combo.valueField]);     }    }    //觸發(fā)選中事件    //combo.fireEvent('select', combo,store.getAt(combo.selectIndex));   },   failure: function (response) {    //請求服務(wù)器失敗   }  }); }});

調(diào)用實(shí)例:

{    xtype: 'baseCombobox',    name: "typeName",    fieldLabel: "類型",    displayField: 'typeName',    valueField: 'id',    emptyIndex:0,    multiSelect:false,    url:"/itemType/list",    listeners:{     select:'query'    }},

這樣大大方便了我使用combobox,如果某種類型的combobox需要重復(fù)使用,建議還是直接定義好他,到需要用的時(shí)候一句:

 xtype: 'itemTypeCombobox',就可以搞定了,代碼看起來簡潔又漂亮。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 铜鼓县| 长海县| 福清市| 衡山县| 增城市| 明星| 萝北县| 青河县| 南昌市| 墨脱县| 巫山县| 微博| 襄汾县| 望奎县| 铜陵市| 木兰县| 宁津县| 汝阳县| 东明县| 讷河市| 治多县| 虹口区| 双牌县| 卢湾区| 自治县| 夏河县| 离岛区| 开封市| 双江| 临猗县| 根河市| 舒城县| 南丰县| 常德市| 沈丘县| 安溪县| 固阳县| 郑州市| 资兴市| 确山县| 红原县|