2014-11-06 38 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