简体   繁体   English

如何使用`document.querySelector()`访问ExtJS元素?

[英]How can I access ExtJS elements using `document.querySelector()`?

I'm attempting to integrate the http://www.dropzonejs.com/ file uploader into an existing ExtJS 3.4 application. 我正在尝试将http://www.dropzonejs.com/文件上传器集成到现有的ExtJS 3.4应用程序中。 I'm running into problems, as the elements created by ExtJS do not seem to be available using native document. 我遇到了问题,因为使用本机document.似乎无法使用ExtJS创建的元素document. methods, used by DropzoneJS. DropzoneJS使用的方法。

I want to render the upload panel inside a dynamically created ExtJS window: 我想在动态创建的ExtJS窗口中呈现上载面板:

App.DropzoneWindow = function(config) {
    config = config || {};
    Ext.applyIf(config, {
        url: App.config.connectorUrl
        ,dropzone: null
        ,base_params: {}
    });
    OB.DropzoneWindow.superclass.constructor.call(this, config);
    this.dropzone = this.initDropzoneJs();
};
Ext.extend(App.DropzoneWindow, App.Window, {
    initDropzoneJs: function() {
        var config = {
            url: this.url
        };
        return new Dropzone('div#'+this.id, config);
    }
});
Ext.reg('app-dropzone-window', App.DropzoneWindow);

Dropzone.js is throwing an error "Invalid dropzone element" immediately, as it's trying to access my target window element using document.querySelector() . Dropzone.js尝试使用document.querySelector()访问我的目标窗口元素时,立即抛出错误“无效的dropzone元素”。 Here are the lines in throwing the error in the source code: 以下是在源代码中引发错误的行:

https://github.com/enyo/dropzone/blob/master/downloads/dropzone.js#L636-L640 https://github.com/enyo/dropzone/blob/master/downloads/dropzone.js#L636-L640

Any ideas how I can achieve this without modifying the Dropzone.js source? 有什么想法可以在不修改Dropzone.js源代码的情况下实现这一目标吗?

I think the problem is that you are trying to access elements before panel is rendered, so that will never give you elements 我认为问题在于,您正在尝试在渲染面板之前访问元素,这样就永远不会给您元素

use afterrender event to initialize DropZone.js 使用afterrender事件初始化DropZone.js

App.DropzoneWindow = function(config) {
    config = config || {};
    Ext.applyIf(config, {
        renderTo : Ext.getBody(),
        listeners : {
             afterrender : this.initDropzoneJs,
             scope : this
        }
    });

    OB.DropzoneWindow.superclass.constructor.call(this, config);
};
Ext.extend(App.DropzoneWindow, App.Window, {
    initDropzoneJs: function() {
        var config = {
            url: this.url
        };
        return new Dropzone('div#'+this.id, config);
    }
});
Ext.reg('app-dropzone-window', App.DropzoneWindow);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我的表单与document.querySelector相关联? - How can I associate my form with document.querySelector? 如何使用document.querySelector使用document.querySelector从节点中选择文本的特定输出? - How do I use document.querySelector to select a particular output of text from a node using document.querySelector? 不在DOM中的元素上的document.querySelector()? - document.querySelector() on elements not in DOM? 在 document.queryselector 中使用变量 - using a variable in document.queryselector 如何实现document.querySelector? - How is document.querySelector implemented? 我不能添加超过 2 个 document.querySelector().addEventListener() - I can't add document.querySelector().addEventListener() more than 2 Document.querySelector() 未显示所有元素 - Document.querySelector() is not showing all elements 在 React 中使用 document.querySelector? 我应该使用 refs 吗? 如何? - Using document.querySelector in React? Should I use refs instead? How? 如何根据“color”属性获取带有“document.querySelector”的特定元素? - How can i get specific element with 'document.querySelector' according to 'color' property? 如何将 document.querySelector 用于 select 这个 class 名称,其中有空格? - How can I use document.querySelector to select this class name with a space in it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM