Free and Open source Web Builder Framework. Next generation tool for building templates without coding
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
801 B

import { each } from 'underscore';
import { Model, Collection } from '../../common';
export default class JsonGenerator extends Model {
build(model) {
var json = model.toJSON();
this.beforeEach(json);
each(
json,
function (v, attr) {
var obj = json[attr];
if (obj instanceof Model) {
json[attr] = this.build(obj);
} else if (obj instanceof Collection) {
var coll = obj;
json[attr] = [];
if (coll.length) {
coll.each(function (el, index) {
json[attr][index] = this.build(el);
}, this);
}
}
},
this
);
return json;
}
/**
* Execute on each object
* @param {Object} obj
*/
beforeEach(obj) {
delete obj.status;
}
}