Improve GroupsList each() method and use it in count() and export() methods

This commit is contained in:
Benjamin Renard 2014-01-12 20:08:27 +01:00
parent 13f3db00d5
commit cc37ad1ffc

View file

@ -28,13 +28,9 @@ function GroupList() {
} }
this.export=function() { this.export=function() {
ret={}; return this.each(function(idx,group) {
for (el in this) { return group.export();
if (this.isGroup(this[el])) { });
ret[el]=this[el].export();
}
}
return ret;
} }
this.import=function(groups) { this.import=function(groups) {
@ -60,18 +56,20 @@ function GroupList() {
this.each=function(fct) { this.each=function(fct) {
var idx=0; var idx=0;
var ret={};
for (el in this) { for (el in this) {
if(this.isGroup(this[el])) { if(this.isGroup(this[el])) {
fct(idx++,this[el]); ret[el]=fct(idx++,this[el]);
} }
} }
return ret;
} }
this.count=function() { this.count=function() {
len=0; len=0;
for (el in this) { this.each(function(idx,group) {
if (this.isGroup(this[el])) len=len+1; len=len+1;
} });
return len; return len;
} }