• EXTJS7 实现点击拖拉选择文本


    默认情况下,用户无法通过点击拖拉选择界面上的文本

    解决方案

    1. Ext.Component组件可以使用userSelectable配置项,设置为‘text’,即可实现此组件中文本的点选
      注意:如果设置为true,等效于设置样式 user-select: auto; ,将根据浏览器默认属性进行选择
    {
    	xtype: 'grid',
    	userSelectable: 'text'
    }
    

    也可以传入对象设置子元素的样式

    userSelectable: {
       element: true,       // allow the element to be user selectable
       bodyElement: true    // allow the component's body element to be user selectable
    }
    
    1. Ext.Component组件可以使用userCls配置项,添加 Ext.baseCSSPrefix + ‘user-selectable-text’ 样式类
    {
    	xtype: 'grid',
    	columns: [{
    		cell: { userCls: Ext.baseCSSPrefix + 'user-selectable-text' }
    	}]
    }
    

    源码解析

    Ext.define('Ext.Component', {
    	// userSelectable 各属性值对应的样式类
    	userSelectableClsMap: {
            true: Ext.baseCSSPrefix + 'user-selectable-auto',
            false: Ext.baseCSSPrefix + 'user-selectable-none',
            all: Ext.baseCSSPrefix + 'user-selectable-all',
            auto: Ext.baseCSSPrefix + 'user-selectable-auto',
            text: Ext.baseCSSPrefix + 'user-selectable-text',
            none: Ext.baseCSSPrefix + 'user-selectable-none'
        },
        updateUserSelectable: function(newSelectable, oldSelectable) {
            var me = this,
                map = me.userSelectableClsMap,
                el = me.el,
                name, childEl;
     
            if (typeof oldSelectable === 'boolean' || typeof oldSelectable === 'string') {
                el.removeCls(map[oldSelectable]);
            }
            else {
                for (name in oldSelectable) {
                    childEl = me[name];
     
                    //<debug>
                    if (!childEl || !childEl.isElement) {
                        Ext.raise('Element not found: "' + name + '"');
                    }
                    //</debug>
     
                    childEl.removeCls(map[oldSelectable[name]]);
                }
            }
     
            if (typeof newSelectable === 'boolean' || typeof newSelectable === 'string') {
            	// 如果传入为布尔或字符串,直接添加对应的样式类
                el.addCls(map[newSelectable]);
            }
            else {
            	// 如果传入的是对象,则根据对象属性分别给子元素添加样式类
                for (name in newSelectable) {
                    childEl = me[name];
     
                    //<debug>
                    if (!childEl || !childEl.isElement) {
                        Ext.raise('Element not found: "' + name + '"');
                    }
                    //</debug>
     
                    childEl.addCls(map[newSelectable[name]]);
                }
            }
        },
    });
    
  • 相关阅读:
    MVC提交时验证
    远程计划任务管理
    教你一步一步部署.net免费空间OpenShift系列之四------绑定域名、使用CDN加速
    启用IIS7报错功能
    教你一步一步部署.net免费空间OpenShift系列之三------上传ASP.net程序
    教你一步一步部署.net免费空间OpenShift系列之二------创建应用
    Spring SimpleJdbcOperations 批量更新
    c#获取已安装的所有NET版本
    (转载)数据库效率提高的方案
    linux两台服务器之间文件/文件夹拷贝
  • 原文地址:https://www.cnblogs.com/luguojun/p/14294651.html
Copyright © 2020-2023  润新知