Sha256: b3e938cbd0956675aad29ff523bb531702abd19d1b68125cc0b20a41328b2189
Contents?: true
Size: 1.09 KB
Versions: 9
Compression:
Stored size: 1.09 KB
Contents
HAL.Models.Resource = Backbone.Model.extend({ initialize: function(representation) { representation = representation || {}; this.links = representation._links; if(representation._embedded !== undefined) { this.embeddedResources = this.buildEmbeddedResources(representation._embedded); } this.set(representation); this.unset('_embedded', { silent: true }); this.unset('_links', { silent: true }); }, buildEmbeddedResources: function(embeddedResources) { var result = {}; _.each(embeddedResources, function(obj, rel) { if($.isArray(obj)) { var arr = []; _.each(obj, function(resource, i) { var newResource = new HAL.Models.Resource(resource); newResource.identifier = rel + '[' + i + ']'; newResource.embed_rel = rel; arr.push(newResource); }); result[rel] = arr; } else { var newResource = new HAL.Models.Resource(obj); newResource.identifier = rel; newResource.embed_rel = rel; result[rel] = newResource; } }); return result; } });
Version data entries
9 entries across 9 versions & 1 rubygems