itemsByValue method

This commit is contained in:
vitalets
2012-12-28 18:05:09 +04:00
parent 5f3f820312
commit d4d2bf930a
7 changed files with 47 additions and 28 deletions

@ -124,6 +124,28 @@
**/
escape: function(str) {
return $('<div>').text(str).html();
},
/*
returns array items from sourceData having value property equal or inArray of 'value'
*/
itemsByValue: function(value, sourceData) {
if(!sourceData || value === null) {
return [];
}
if(!$.isArray(value)) {
value = [].push(value);
}
/*jslint eqeq: true*/
var result = $.grep(sourceData, function(o){
return $.grep(value, function(v){ return v == o.value; }).length;
});
/*jslint eqeq: false*/
return result;
}
};
}(window.jQuery));