2011-04-04 27 views
2

我有一個關於xtypes的問題。當我這樣做:Sencha xtype方法

// map 

var map = new Ext.map({ 
    fullscreen: true, 
    getLocation: true, 
    mapOptions: { 
     zoom: 12 
    } 
}); 

map.map.setCenter(new google.maps.LatLng(record.attributes.record.data.latitude, record.attributes.record.data.longitude)); 

一切都很好,地圖顯示。

現在,當我使用xtypes時,'map'變量將無法識別'setCenter'屬性。 代碼: VAR地圖= { 全屏:真實, 的xtype: '地圖', 標題: '地圖', 的getLocation:真實, useCurrentLocation:真實, 的MapOptions: { 變焦:12 } };

map.map.setCenter(new google.maps.LatLng(record.attributes.record.data.latitude, record.attributes.record.data.longitude)); 

有了這個代碼,我得到這個在控制檯:

Uncaught TypeError: Cannot call method 'setCenter' of undefined

我希望有人能幫助我。提前致謝!

回答

3

當您致電map.map.setCenter()時,您的地圖對象已被實例化。通過用xtype定義你的映射,使用懶惰的實例化。

你可以嘗試沿着線somethign:

{ 
    xtype: 'map', 
    fullscreen: true, 
    getLocation: true, 
    mapOptions: { 
     zoom: 12 
    }, 
    listeners: { 
     maprender: function(component, map) { 
      map.setCenter(...) 
     } 
    } 
} 
+0

謝謝您的回答!我正在玩xtypes,現在我和麪板一樣。 //描述 變種描述= { \t的xtype: '面板', \t TPL: '{TITLE}' }; \t \t \t \t \t \t \t description.update(record.attributes.record.data); 這給了我一個錯誤,方法'更新'不知道...我是否必須以同樣的方式解決這個問題? – Voles 2011-04-04 11:17:50

+1

是的,我相信是的。在文檔中,您可以查看可插入面板的不同事件(例如,maprender是Map的事件)。 – Nicodemuz 2011-04-04 15:57:32