-
Notifications
You must be signed in to change notification settings - Fork 0
/
RockFinder2.js
43 lines (38 loc) · 920 Bytes
/
RockFinder2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* RockFinder2 JavaScript Object
*/
function _RockFinder2(json) {
// global config
this.conf = {};
this.data = {};
if(json) this.data = JSON.parse(json);
};
/**
* Return options for given field
*/
_RockFinder2.prototype.getOptions = function(name) {
var name = name || null;
if(!name) return this.data.options;
return this.data.options[name] || [];
}
/**
* Return option by id
*/
_RockFinder2.prototype.getOption = function(name, id) {
return this.getOptions(name)[id];
}
_RockFinder2.prototype.getRelation = function(name) {
return this.data.relations[name];
}
/**
* Get relation data
*/
_RockFinder2.prototype.getRelationData = function(relation, field, value) {
var relationData = this.getRelation(relation).data;
var result = [];
for(var i=0; i<relationData.length; i++) {
var item = relationData[i];
if(item[field] == value) result.push(item);
}
return result;
}