2016-06-21 26 views
1

我需要访问剪贴板上的Extjs Combobox中的keydown事件的数据,以执行某些操作。
我试着用window.clipboardData。 请找到小提琴:https://fiddle.sencha.com/#fiddle/1cc2Extjs6:在Keydown事件的组合框中获取剪贴板数据

Ext.create('Ext.form.field.Tag',{ 
    renderTo:Ext.getBody(), 
    createNewOnEnter:true, 
    store:[1,2,3], 
    enableKeyEvents:true, 
    listeners:{ 
     keydown:function(combo,e){ 
      if(e.getKey() === e.V && e.ctrlKey){ 
       //get Clipboard data here 
       combo.preventKeyUpEvent = e.V; 
       e.stopEvent(); 
      } 
     } 
    } 
}); 

回答

1

不知道你做错了,但它确实在我的IE11的工作,如果我添加console.log(window.clipboardData)到您的提琴:

Ext.application({ 
    name : 'Fiddle', 

    launch : function() { 
     Ext.create('Ext.form.field.Tag',{ 
      renderTo:Ext.getBody(), 
      createNewOnEnter:true, 
      store:[1,2,3], 
      enableKeyEvents:true, 
      listeners:{ 
       keydown:function(combo,e){ 

        if(e.getKey() === e.V && e.ctrlKey){ 
         console.log(window.clipboardData); 
         combo.preventKeyUpEvent = e.V; 
         e.stopEvent(); 
        } 
       } 
      } 
     }); 
    } 
}); 

我不建议使用它,不过,因为window.clipboardData只是IE。您应该使用W3C clipboard API instead,这是一个标准草案和already implemented in all recent browsers

+0

感谢您的时间亚历克斯。我想用extjs控制。 –

4

我想你可以添加paste事件侦听器,您的组合(其选择器实际上)和使用ClipboardEvent接口的方法,这样得到剪贴板数据:

combo.getEl().addListener(
    'paste', 
    function(event, element, options) { 
     var clipboardData = event.browserEvent.clipboardData; 
     console.log(clipboardData.getData('Text')); 
    } 
); 

Working fiddle

+0

谢谢谢尔盖..这是工作,我在找什么。 –