默认情况下,用户无法通过点击拖拉选择界面上的文本
{
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
}
{
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]]);
}
}
},
});