简体   繁体   English

单击面板时如何在ext js面板中添加项目?

[英]How to add an item to ext js panel on click of the panel?

I want to add a button into a panel to the exact position where I clicked. 我想将一个按钮添加到面板中我单击的确切位置。

SO I have tried like as follows, this the structure of my Ext.widget element 所以我尝试如下,这是我的Ext.widget元素的结构

Ext.widget({ xtype : 'mz-form-widget', itemId: 'shopableImage', anchor: "100%", Ext.widget({xtype:'mz-form-widget',itemId:'shopableImage',锚点:“ 100%”,

    defaults: {
        xtype: 'textfield',
        listeners: {
            controller: '',
            change: function (cmp) {
                controller = cmp;
                cmp.up('#shopableImage').updatePreview();
            }
        }
    },


    items: [
        {
            xtype: "tacofilefield",
            itemId: "imageUploadButton",
            text: "Upload images"
        },
        {
            xtype: 'panel',
            width: 350,
            height: 350,
            itemId:'container',
            id:'container',
            bodyStyle:{"background":"url('http://www.easyvectors.com/assets/images/vectors/vmvectors/jeans-girl-vector-27.jpg')","border":"1px solid #eee"},
            listeners: {
                click: {
                    element: 'el', //bind to the underlying el property on the panel
                    fn: function(a,b,c,d){ 
                        console.log(a.browserEvent.clientX - b.offsetLeft);
                        console.log(a.browserEvent.clientY - b.offsetTop);
                        console.log(c);
                       this.down('#container').addItem({"xtype":"button","text":"+"});
                    }
                },
                dblclick: {
                    element: 'body', //bind to the underlying body property on the panel
                    fn: function(){ console.log('dblclick body'); }
                }
            }
        }

The following line throwing me error. 以下行引发我错误。 this.down('#container').addItem({"xtype":"button","text":"+"}); UPDATE UPDATE

this.down('#container')

is returning null. 返回null。

Please give me your suggestions regarding this? 请给我您的建议吗?

There are two problems here, one is causing the error and another is a potential time bomb: 这里有两个问题,一个导致错误,另一个是潜在的定时炸弹:

  1. addItem does not exist, the correct method name is add addItem不存在,正确的方法名称是add
  2. You use id's on components and that is a very bad practice, however, it does not the immediate cause of the error 您在组件上使用id是一个非常糟糕的做法,但是,它不是错误的直接原因

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

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