-
15 Aug 2009 7:26 AM #1
Unanswered: jQuery equivalent
Unanswered: jQuery equivalent
Hello,
How to write this jQuery-Code in Ext?
Thank you in advancePHP Code:$('a').filter(function() {
return this.hostname != location.hostname;
}).addClass('external');
-
15 Aug 2009 8:17 AM #2Sencha - Ext JS Dev Team
- Join Date
- Mar 2007
- Location
- Notts/Redwood City
- Posts
- 30,458
- Vote Rating
- 20
- Answers
- 9
First off, what does it do?
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
15 Aug 2009 8:41 AM #3Sencha - Ext JS Dev Team
- Join Date
- Mar 2007
- Location
- Notts/Redwood City
- Posts
- 30,458
- Vote Rating
- 20
- Answers
- 9
OK, a bit of digging reveals a lacuna in Ext's CompositeElement abilities. A filter function which filters by a passed function is an obvious need.
You need to add at the top of your page
Then you would doCode:// Add a filter function to CompositeElement (Why it not there already?) Ext.override(Ext.CompositeElementLite, { filter : function(fn){ var els = []; this.each(function(el){ if(fn(el.dom)){ els[els.length] = el.dom; } }); this.elements = []; this.add(els); return this; } });
Code:Ext.select("a").filter(function(a) { return a.hostname != location.hostname }).addClass("external");Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
15 Aug 2009 8:44 AM #4
Thank you but "this.fill is not a function..."
-
15 Aug 2009 9:00 AM #5Sencha - Ext JS Dev Team
- Join Date
- Mar 2007
- Location
- Notts/Redwood City
- Posts
- 30,458
- Vote Rating
- 20
- Answers
- 9
A more Exty way to do it is to add a psdueo-class selection function to DomQuery. This would be like the :nth-child pseudo class, so you would add to the top of your page.
And then the simple and obvious code:Code:// Ext's DOM query aparatus allows definition of new pseudo classes. Ext.DomQuery.pseudos.external = function(c, v){ var r = [], ri = -1; for(var i = 0, ci; ci = c[i]; i++){ if(ci.hostname != location.hostname){ r[++ri] = ci; } } return r; };
There are always several ways to skin a cat in Ext!Code:Ext.select("a:external").addClass("external");Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
15 Aug 2009 9:12 AM #6
Quote from "Learning jQuery 1.3":
"...Also the .filter() method in particular had enormous power because it can take a function as it argument. The function allows us to create complex tests for whether elements should be kept in the matched set. Let's suppose, for example, we want to add a class to all external links..."
Is there no simple equivalent in Ext?
-
15 Aug 2009 11:37 AM #7Sencha - Ext JS Dev Team
- Join Date
- Mar 2007
- Location
- Notts/Redwood City
- Posts
- 30,458
- Vote Rating
- 20
- Answers
- 9
Have you been reading my replies? You can use the pseudo.
I just updated the code in post #3 code for the filter function to adjust for the absence of the fill method.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
15 Aug 2009 11:41 AM #8Sencha - Ext JS Dev Team
- Join Date
- Mar 2007
- Location
- Notts/Redwood City
- Posts
- 30,458
- Vote Rating
- 20
- Answers
- 9
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
15 Aug 2009 12:02 PM #9
-
15 Aug 2009 6:27 PM #10Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,066
- Vote Rating
- 96
- Answers
- 166
I was doing some stuff with Core the other day, the filter() method should definitely be there.
And it will be in the next build
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!


Reply With Quote