How can I get JQuery/Javascript access to elements generated by extJS?

為{幸葍}努か 提交于 2019-12-05 22:48:54

Try using the delegate method provided by jQuery.

JQuery("body").delegate("#myPanel", "click", function(){
    //Your handler
});

Find more details here learningjquery jquery api

I've not tested this code, but just another direction you can look into

Quick tip: Try using Ext.getCmp() instead of Ext.get()

Better tip: See this: http://vimeo.com/14816550

Brian Moeskau

Please see my answer to your other (duplicate?) question.

Looking at the code in this question (which you didn't fully post in the other question) the reason Ext.get() and Ext.getCmp() are not working for you is that the Panel is not yet rendered at the time you're calling them (that's why the calls return null). Since you are adding the Panel definitions into the viewport as items, they don't get rendered until the viewport is instantiated and rendered (this is a specific benefit of Ext, that it supports lazy-rendering for performance purposes). So to fix that, you should simply move any code that has to access the Panel's DOM either after the viewport code, or place it in an event handler for the Panel's render event (as I showed in the linked answer).

The answer you accepted happens to work simply because the attaching of the click handler is delayed for you behind the scenes, but it's not really the correct approach (and there is no need to inject jQuery just for this purpose, unless you're using it for something else).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!