02 Nov 2009 @ 9:30 PM 

Motivation

Ich habe bisher vor allem das JQuery- Javascript Framework benutzt und bin mit Grails zum ersten Mal mit YUI (2)in Berührung gekommen.
Und ich denke es ist eine mehr als unglückliche Wahl.

Syntax#1

Fangen wir mit Groovy an. Nehmen wir mal und das wirklich nur angenommen, der Browser könnte Groovy wie Javascript ausführen.
Wir würde man dann alle “divs” mit der Klasse “selected” eines Dokuments suchen?

def divs = document.findAllByTypeAndClass("div","selected")

Wäre da so meine erste Idee. Ähnlich den Dynamic Finders. Aber das wäre mir nicht “Groovy” genug.
Laut IBM sähe die Lösung etwa so aus:

def divs = document.div.[@class="selected"]

Quasi wie E4X. Bleiben wir einfach mal bei dieser Lösung. Sie ist Groovy genug.

Gehen wir weiter zu YUI

var elements = YAHOO.util.Dom.getElementsByClassName('test', 'div');
oder
var elements = YAHOO.util.Selector.query('div.test');

Und dann zu JQuery

var elements = $("div.selected");

Welches Framework ist nun Grooviger?

Syntax#2

Okay vielleicht ist das Beispiel noch zu einfach. Gehen wir mal weiter und markieren die eben gewählten divs mit einem rotem Hintergrund.

Zunächst wieder Groovy

document.div.[@class="selected"].each(){ it.backgroundcolor="red"}

Schöne und Groovy Lösung! Gehen wir nun über zu YUI

Dom.batch(YAHOO.util.Selector.query('div.test'), function (element) {Dom.setAttribute(element, "background-color","red");});

und dann zu JQuery

$("div.selected").each(function(){$(this).attr("background-color","red");});
//oder sogar
$("div.selected").attr("background-color","red");

Spätestens hier sollte klar werden auf was ich hinaus will. Die JQuery- Syntax passt einfach viel besser zu Groovy und Grails.


Posted By: tkdmatze
Last Edit: 02 Nov 2009 @ 09:33 PM

EmailPermalink
Tags
Categories: grails, Javascript, web 2.0


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


 Last 50 Posts
 Back
Change Theme...
  • Users » 2
  • Posts/Pages » 30
  • Comments » 6
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight