Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function(options) {
- //console.log(this.items);
- var result = [];
- if (!options || (!isNumber(options) && !isObject(options))) {
- throw new Error('You must provide a valid id or options.');
- }
- if (isNumber(options)) {
- result = this.items.filter(function(item) {
- return item.id == options;
- });
- if (result.length > 0) {
- return result[0];
- } else {
- return null;
- }
- } else {
- var isFound = true;
- result = this.items.filter(function(item) {
- //item.id = item._id;
- //item.genre = item._genre;
- //item.name = item._name;
- for (var prop in options) {
- if (options[prop].toString().toLowerCase() != item[prop].toString().toLowerCase()) {
- isFound = false;
- break;
- }
- }
- if (isFound) {
- return item;
- }
- });
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement