- 浏览: 341610 次
- 性别:
- 来自: 广州
文章分类
最新评论
转: http://www.2cto.com/kf/201206/135007.html
/**
*下拉树类(Jelly)
*/
Ext.define('Redm.commons.TreeCombox', {
extend: 'Ext.form.field.Picker',
xtype: 'treecombox',
triggerCls: Ext.baseCSSPrefix + 'form-arrow-trigger',
config: {
displayField: null,
columns: null,
rootVisible: true,
selectOnTab: true,
firstSelected: false,
maxPickerWidth: 300,
maxPickerHeight: 360,
minPickerHeight: 100
},
editable: false,
initComponent: function() {
var me = this;
me.callParent(arguments);
this.addEvents('select');
me.store.on('load', me.onLoad, me);
},
createPicker: function() {
var me = this,
picker = Ext.create('Ext.tree.Panel', {
store: me.store,
floating: true,
hidden: true,
width: me.maxPickerWidth,
displayField: me.displayField,
columns: me.columns,
maxHeight: me.maxTreeHeight,
shadow: false,
rootVisible: me.rootVisible,
manageHeight: false,
listeners: {
itemclick: Ext.bind(me.onItemClick, me)
},
viewConfig: {
listeners: {
render: function(view) {
view.getEl().on('keypress', me.onPickerKeypress, me);
}
}
}
}),
view = picker.getView();
view.on('render', me.setPickerViewStyles, me);
if (Ext.isIE9 && Ext.isStrict) {
view.on('highlightitem', me.repaintPickerView, me);
view.on('unhighlightitem', me.repaintPickerView, me);
view.on('afteritemexpand', me.repaintPickerView, me);
view.on('afteritemcollapse', me.repaintPickerView, me);
}
return picker;
},
setPickerViewStyles: function(view) {
view.getEl().setStyle({
'min-height': this.minPickerHeight + 'px',
'max-height': this.maxPickerHeight + 'px'
});
},
repaintPickerView: function() {
var style = this.picker.getView().getEl().dom.style;
style.display = style.display;
},
alignPicker: function() {
var me = this,
picker;
if (me.isExpanded) {
picker = me.getPicker();
if (me.matchFieldWidth) {
picker.setWidth(this.picker.getWidth());
}
if (picker.isFloating()) {
me.doAlign();
}
}
},
onItemClick: function(view, record, node, rowIndex, e) {
this.selectItem(record);
},
onPickerKeypress: function(e, el) {
var key = e.getKey();
if(key === e.ENTER || (key === e.TAB && this.selectOnTab)) {
this.selectItem(this.picker.getSelectionModel().getSelection()[0]);
}
},
selectItem: function(record) {
var me = this;
me.setValue(record.get(this.valueField || 'id'));
me.picker.hide();
me.inputEl.focus();
me.fireEvent('select', me, record)
},
onExpand: function() {
var me = this,
picker = me.picker,
store = picker.store,
value = me.value;
if(value) {
var node = store.getNodeById(value);
if(node)
picker.selectPath(node.getPath());
} else {
var hasOwnProp = me.store.hasOwnProperty('getRootNode');
if(hasOwnProp)
picker.getSelectionModel().select(store.getRootNode());
}
Ext.defer(function() {
picker.getView().focus();
}, 1);
},
setValue: function(value) {
var me = this,record;
me.value = value;
if (me.store.loading) {
return me;
}
try{
var hasOwnProp = me.store.hasOwnProperty('getRootNode');
record = value ? me.store.getNodeById(value) : (hasOwnProp ? me.store.getRootNode() : null);
me.setRawValue(record ? record.get(this.displayField) : '');
}catch(e){
me.setRawValue('');
}
return me;
},
getValue: function() {
return this.value;
},
onLoad: function(store,node,records) {
var value = this.value;
if (value) {
this.setValue(value);
}else{
if(this.firstSelected){
if(records && records.length > 0){
var record = records[0];
this.setValue(record.get(this.valueField));
}
}
}
},
getSubmitData: function() {
var me = this,
data = null;
if (!me.disabled && me.submitValue) {
data = {};
data[me.getName()] = '' + me.getValue();
}
return data;
},
onTriggerClick: function() {
var me = this;
//me.store.load();
if (!me.readOnly && !me.disabled) {
if (me.isExpanded) {
me.collapse();
} else {
me.expand();
}
me.inputEl.focus();
}
}
});
使用示例代码
[javascript]
{
name: 'smallType',
fieldLabel: '小类',
xtype: 'treecombox',
valueField: 'id',
displayField: 'text',
store: Ext.create('Ext.data.TreeStore', {
fields: ['text','id','parentId'],
root: {
text: '所有分类',
id: -1,
expanded: true
},
proxy: {
type: 'ajax',
url: '../../basicdata/doQueryAllps.action'
}
})
}
再来个效果图,下拉树的宽度可以自定义,更改属性 maxPickerWidth即可。
发表评论
-
EasyUI和EasyUI桌面App
2013-04-15 11:56 1206http://fxz-2008.iteye.com/blog/ ... -
Jquery进度条
2013-04-12 09:08 874http://www.cnblogs.com/lhb25/ h ... -
11个适合触摸事件开发的JavaScript库
2013-04-10 09:23 834http://www.codecto.com/2012/08/ ... -
Jquery插件
2013-03-22 18:33 791http://www.cnblogs.com/ywqu/arc ... -
宝贝鱼
2013-03-18 23:54 694http://code.google.com/p/cshbbr ... -
HTML&JS MVC
2013-03-15 16:27 626http://www.bootcss.com/ http:// ... -
浏览器内核及Js引擎介绍
2013-03-15 16:18 741http://wenku.baidu.com/view/623 ... -
EXTJS Demo
2013-03-12 17:19 795http://web230531.host89.chinajs ... -
网站架构和两个3d技术
2013-01-17 16:52 0http://blog.csdn.net/lovingprin ... -
DWR数据反推实例
2013-01-16 16:42 1422http://blog.sina.com.cn/s/blog_ ... -
javascript调用服务端方法
2012-12-17 22:03 941http://www.php100.com/html/webk ... -
DWR推送技术
2012-12-13 16:13 10642DWR2.x的推技术也叫DWR Reverse Ajax(逆向 ... -
wireshark 协议过滤
2012-10-09 11:32 1646http://blog.csdn.net/cumirror/a ... -
一个很不错的Javascript绘图库
2012-09-27 17:18 0http://www.jgraph.com/ http://w ... -
dwr推送数据
2012-09-21 16:59 0Dwr数据推技术:http://blog.csdn.net/k ... -
Extjs4 Css美工相关
2012-09-03 10:39 2988转: http://www.sencha.com/lear ... -
Javascript基础一(apply, call, arguments, prototype)
2012-08-22 22:42 1077//javascript: apply, call, argu ... -
Extjs4的事件实例
2012-08-09 09:11 815http://www.cnblogs.com/luluping ... -
EXTJS中的Store是如何工作的
2012-08-08 21:04 979http://idoa3l3x.blogbus.com/log ... -
Extjs中的设计模式
2012-08-03 23:06 2363ExtJS设计模式 在前 ...
相关推荐
[YOLOv7]基于YOLO&Deepsort的人流量统计系统(源码&部署教程)
Recognizecaptchabymachinelearning.机器学习识别图片验证码(专门应付本科毕业设计)_hy5
Python基于CycleGAN&pix2pix的黑白图像AI上色(源码&部署教程)
收录了「IT无知君」CSDN博客中涉及的【Java项目源码】,还有许多的开发工具类,都是我自己在用在不断维护的,需要请进!_hy5
coderwhycms后台接口使用nestjs+mysql+typeorm-prisam+docker+jwt+re_hy4
Java轻量化RBAC权限控制系统_hy4
3个小项目分别是利用Python实现报表自动化、某连锁超市、某银行数据分析,展示了问题分解、数据清洗、数据分析与可视化的过程。_hy4
前端分析-2023071100789
330 Series Campus Access Points IAP-334 IAP-335
【Swift】swift项目仿写喜马拉雅App,采用MVC+MVVM设计模式
ebay的python爬虫_hy4
【Java】一套自定义的RBAC权限管理框架,基于SpringMVC,mybatis_pgj
【go】基于微服务框架go-micro封装的go微服务脚手架_pgj
分布式事务-seata_hy5
【Java】jta分布式事务+多数据源_pgj
python写的12306爬虫,用的tkinter做可视化界面_hy5
音乐推荐系统,python编写,涉及flask框架,scrapy爬虫,MySQL数据库,selenium,chrome_hy4
Python网络爬虫从入门到放弃_hy4
318 Series Hardened Access Points 370 Series Outdoor Access Points 387 Series Outdoor Access Points 320 Series Campus Access Points 310 Series Campus Access Points IAP-315 IAP-325 IAP-324 IAP-314
最全的JAVA设计模式,包含原理图解+代码实现_hy5