For example, I am making a select box that lists users alphabetically. Users are identified in the database by an id:
var foo = new Element('select').inject($$('body')[0]);
var options = {5082:'User A', 5085:'User B', 5074:'User C'}
$H(options).each(function(name,id){
new Element('option', {text:name, value:id}).inject(foo);
});
/*
Function: Hash.sort
Takes {c:0, a:1, b:2} and returns [{a:1},{b:2},{c:0}]
*/
Hash.Implement({
sort:function(fn){
var out = [],
keysToSort = this.getKeys(),
m = this.getLength();
(typeof fn == 'function') ? keysToSort.sort(fn) : keysToSort.sort();
for (var i=0; i<m; i++){
var o = {};
o[keysToSort[i]] = this[keysToSort[i]];
out.push(o);
}
return out;
}
});
____________ });
Usage:
$H({'a':1,'z':2,'c':3,'b':4}).sort()
Results In:
[Object { a=1}, Object { b=4}, Object { c=3}, Object { z=2}]
______________________
Then our select box routine becomes:
var foo = new Element('select').inject($$('body')[0]);
var options = {5082:'User A', 5085:'User B', 5074:'User C'}
$H(options).sort().each(function(el){
$each(el,function(name, id){
new Element('option', {text:name, value:id}).inject(foo);
});
});
_______ Ruby programmers may recognize this method (http://ruby-doc.org/core/
classes/Hash.html#M002865).
Great Article
ReplyDeleteJavaScript Training | Javascript Courses | Typescript Training in Chennai | Node.js Training in Chennai | Backbone.JS Training in Chennai | Angularjs Training in Chennai | HTML5 Training in Chennai | JavaScript Training in Chennai
IVR Plugin solution is a competent automated interactive voice response & speech recognition software which adhibit automated technology.
ReplyDeleteSo, you will be ready http://www.unitedcheckcashing.com to notice U.S.A. all time check cashing close to Pine Tree State supplying you with the only services with one hundred pc satisfaction within really short quantity.
ReplyDeletecheck cashing near me
ReplyDeleteافضل شركة كشف تسربات المياه بالمدينة المنورة شركات كشف تسربات المياه بالمدينة المنورة
شركة كشف تسربات المياه بالاحساء شركة كشف تسربات المياه بالاحساء
شركة مكافحة حشرات بالرياض شركة مكافحة حشرات بالرياض
شركة رش مبيدات بالرياض شركة رش مبيدات بالرياض
You can book call girl in Guwahati or escort Service in Guwahati for incall facility or
ReplyDeleteoutcall Facility as and when required.To book Guwahati call girls you
can visit the following links
Escort Service in Guwahati
Call Girl Service in Guwahati