溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

利用EXTJS7怎么實現(xiàn)一個拖拉文本選擇功能

發(fā)布時間:2020-12-18 14:24:14 來源:億速云 閱讀:185 作者:Leah 欄目:開發(fā)技術

利用EXTJS7怎么實現(xiàn)一個拖拉文本選擇功能?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

解決方案

Ext.Component組件可以使用userSelectable配置項,設置為‘text',即可實現(xiàn)此組件中文本的點選
注意:如果設置為true,等效于設置樣式 user-select: auto; ,將根據(jù)瀏覽器默認屬性進行選擇
{
 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
}

非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 {
   // 如果傳入的是對象,則根據(jù)對象屬性分別給子元素添加樣式類
   for (name in newSelectable) {
    childEl = me[name];
 
    //<debug>
    if (!childEl || !childEl.isElement) {
     Ext.raise('Element not found: "' + name + '"');
    }
    //</debug>
 
    childEl.addCls(map[newSelectable[name]]);
   }
  }
 },
});

看完上述內容,你們掌握利用EXTJS7怎么實現(xiàn)一個拖拉文本選擇功能的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI