-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYAHOO_DataSource_patch.js
70 lines (49 loc) · 1.94 KB
/
YAHOO_DataSource_patch.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
///////////////////////////////////////////////////////////////
///
/// DataSource additional method
///
/// Allows easy parsing of fields using parsers in responseSchema
///
///////////////////////////////////////////////////////////////
(function() {
var Lang = YAHOO.lang;
YAHOO.util.DataSourceBase.prototype._parserCache = null;
/**
* @method parseField
* @public
* @description Provides parsing of a field value at any time.
* @param String Key value for the field
* @param Mixed Value of the field to parse
* @return Mixed Parsed value if parser exists; value as-is if not
*/
YAHOO.util.DataSourceBase.prototype.parseField = function(k, value) {
var i,
fields = this.responseSchema.fields,
p,
pc = this._parserCache;
// build the field-parser cache
if (pc === undefined || pc === null || pc[k] === undefined) {
pc = {};
for (i=0; i<fields.length; i=i+1) {
// Already there - don't need it again
if (pc[fields[i].key] !== undefined) {
continue;
}
p = undefined;
if (Lang.isObject(fields[i])) {
p = (typeof fields[i].parser === 'function' ?
fields[i].parser :
YAHOO.util.DataSource.Parser[fields[i].parser+'']) || fields[i].converter;
if (p !== undefined) {
pc[fields[i].key] = p;
}
}
}
this._parserCache = pc;
}
if (pc[k] !== undefined) {
return pc[k](value);
}
return value;
};
}());