简体   繁体   English

document.Body ComponentQuery

[英]document.Body ComponentQuery

I am using an awesome html2canvas function but I have a noob question. 我正在使用一个很棒的html2canvas函数,但是我有一个菜鸟问题。 How do I change the field it is capturing from document.body to a specific panel? 如何将其从document.body捕获的字段更改为特定面板? In short i need to change document.body to the panel I want to capture, I just don't know the code to get the panel I want. 简而言之,我需要将document.body更改为我要捕获的面板,我只是不知道获取我想要的面板的代码。

I have tried Ext.ComponentQuery.query('#testPanel') without any success. 我尝试了Ext.ComponentQuery.query('#testPanel'),但没有成功。

testButtonClicked: function (btn) {

    html2canvas(document.body, {
        onrendered: function (canvas) {
            new Ext.Window({
                title: 'Screenshot',
                //width: 500,
                height: 800,
                resizable: true,
                autoScroll: true,
                preventBodyReset: true,
                html: '<img src="' + canvas.toDataURL("image/png") + '" height="800"/>'
            }).show();
        }
    });

You want getEl().dom. 您需要getEl()。dom。 Here's a standalone example (tested with Ext 4.2.x): 这是一个独立的示例(经过Ext 4.2.x测试):

Ext.onReady(function () {

    Ext.define('Panel', {
        extend: 'Ext.panel.Panel',

        frame: true,
        title: 'Test Panel',
        width: 300,
        height: 300,

        onClick: function () {
            html2canvas(this.getEl().dom, {
                onrendered: function (canvas) {
                    new Ext.Window({
                        title: 'Screenshot',
                        width: 300,
                        height: 300,
                        html: '<img src="' + canvas.toDataURL("image/png") + '"/>'
                    }).show();
                }
            });
        },


        initComponent: function () {
            var config = {
                items: [
                    {
                        xtype: 'datepicker'
                    },
                    {
                        xtype: 'button',
                        text: 'CAPTURE THIS PANEL',
                        handler: this.onClick,
                        scope: this
                    }
                ]
            };

            Ext.apply(this, Ext.apply(this.initialConfig, config));
            this.callParent(arguments);
        }
    });


    var panel = Ext.create('Panel', {
        renderTo: Ext.getBody()
    });
});

html2canvas() appears to require a DOM element. html2canvas()似乎需要DOM元素。 Ext.ComponentQuery.query() returns an array of matched elements, so if you use precisely the code you provided, it won't work since the array returned from query() is obviously not a DOM element. Ext.ComponentQuery.query()返回匹配元素的数组,因此,如果您精确地使用提供的代码,则由于query()返回的数组显然不是DOM元素,因此它将不起作用。

So if query() is actually returning something, you could use the first position: 因此,如果query()实际上返回了某些内容,则可以使用第一个位置:

Ext.ComponentQuery.query("#testPanel")[0]

Or, since you seem to have an ID assigned to the panel, you could simply use getCmp(), which will return only the element which is matched, and not an array: 或者,由于您似乎已为面板分配了一个ID,因此可以简单地使用getCmp(),该方法将仅返回匹配的元素,而不返回数组:

Ext.getCmp( "testPanel" )

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM