DataDriver.json¶
-
class
webix.DataDriver.
json
()¶ Datadriver.json mixin
References¶
- helpers
assert_error()
,isArray()
,log()
,uid()
.
Referenced by¶
- mixins
AtomDataLoader()
.
External references¶
Code¶
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 | webix.DataDriver.json={
//convert json string to json object if necessary
toObject:function(data){
if (!data) return null;
if (typeof data == "string"){
try{
if (this.parseDates){
var isodate = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d{1-3})?Z/;
data = JSON.parse(data, function(key, value){
if (typeof value == "string"){
if (isodate.test(value))
return new Date(value);
}
return value;
});
} else {
data =JSON.parse(data);
}
} catch(e){
webix.log(e);
webix.log(data);
webix.assert_error("Invalid JSON data for parsing");
return null;
}
}
return data;
},
//get array of records
getRecords:function(data){
if (data && data.data)
data = data.data;
if (data && !webix.isArray(data))
return [data];
return data;
},
//get hash of properties for single record
getDetails:function(data){
if (typeof data == "string")
return { id:(data||webix.uid()), value:data };
return data;
},
getOptions:function(data){
return data.collections;
},
//get count of data and position at which new data need to be inserted
getInfo:function(data){
return {
size:(data.total_count||0),
from:(data.pos||0),
parent:(data.parent||0),
config:(data.config),
key:(data.webix_security)
};
},
child:"data",
parseDates:false
};
|