Hi guys,
I want to know how to improve the following script:
function openJSON() {
deferred = loadJSONDoc('json/Cities');
deferred.addCallback(function (json) {
function getName(x) { return x.name; }
var newUL = UL(null);
for (i=0; i<json.length; i++) {
newLI = LI(null, A({'href':'test?id=' + json[i].id},
json[i].name));
appendChildNodes(newUL, newLI);
}
swapDOM('test', newUL);
});
}
I use the "map" function to do the improve:
function openJSON() {
deferred = loadJSONDoc('json/Cities');
deferred.addCallback(function (json) {
function createLI(item) {
return LI(null, A({'href':'test?id=' + item.id}, item.name));
}
var newUL = UL(null, map(createLI, json));
swapDOM('test', newUL);
});
}
I want to know if there is some advantage except to the less code
script, is there any performace gain? I want to know if there is a way
to do a lambda function inside a map (as I can do in python), I think
in something like:
function openJSON() {
deferred = loadJSONDoc('json/Cities');
deferred.addCallback(function (json) {
var newUL = UL(null, map(lambda(x, LI(null,
A({'href':'test?id='+x.id}, x.name))), json));
swapDOM('test', newUL);
});
}
Is there a way to implement this code?
Thanks in advance!
--
Michel Thadeu Sabchuk
Curitiba - Brasil
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---