2014-11-06 44 views
0

我需要找出动态创建的容器的绝对位置,它们被添加到面板中。ExtJS:获取动态容器的绝对位置

var activityContainer = Ext.create('Ext.Container', { 
    html: activityName, 
    width: ACTIVITY_WIDTH, 
    height: ACTIVITY_HEIGHT, 
    margin: topMargin + ' 0 0 0', 
    cls: 'activity', 
    listeners: { 
     render: function() { 
      this.getEl().dom.title = 'Name: ' + activity.name + reqQuicktip; 
     }, 
     afterrender: function() { 
      console.log('Y: ' + this.getEl().getTop() +' X: '+ this.getEl().getLeft()) 
     } 
    } 
}) 

tradePanel.add(activityContainer); 

我已经知道,只有当容器已经被渲染时,我才能得到位置。因此我使用afterrender监听器。方法getY()/ getTop()等不能按我期望的方式工作。我总是得到1我的x坐标和没有足够的y坐标。

我在这里失踪了什么?

谢谢!

回答

0

根据您如何实现面板,关键字this可能会返回错误面板的信息。

你创建你的听众是这样的:

afterrender: function(component) { 
    console.log('Y: ' + component.getY() +' X: '+ component.getX()); 
} 

这里是一个小提琴为你测试:https://fiddle.sencha.com/#fiddle/cud

+0

好吧。我已经这样实现了,但仍然得到了相同的结果。 – Legenzoo 2014-11-06 20:56:00

+0

你认为你可以提供一个小问题,所以我可以看看? – 2014-11-06 20:57:37

+0

https://fiddle.sencha.com/#fiddle/d01 我意识到我得到的位置相对于面板中的最后一项,但不是绝对的。 = / – Legenzoo 2014-11-07 01:45:41