Internally at Linn, we use convenience functions for retrieving the href value of a given relation by name.
Backbone.Model.prototype.rel = function (name) {
if (!this.has('links')) {
return null;
}
var link = $.grep(this.get('links'), function (l) { return l.rel == name; });
if (link.length > 0) {
return link[0].href;
}
return null;
};
This would be a useful addition to backbone.hypermedia, in addition to a rels function which would return an array of href values based on name:
Backbone.Model.prototype.rels = function (name) {
if (!this.has('links')) {
return [];
}
return $.grep(this.get('links'), function (l) { return l.rel === name; });
};
The implementations above are pulled from two separate code bases - in adding this to backbone.hypermedia, I'm sure we can implement the rel function by making use of the rels function to avoid duplication.
Internally at Linn, we use convenience functions for retrieving the
hrefvalue of a given relation by name.This would be a useful addition to backbone.hypermedia, in addition to a
relsfunction which would return an array ofhrefvalues based on name:The implementations above are pulled from two separate code bases - in adding this to backbone.hypermedia, I'm sure we can implement the
relfunction by making use of therelsfunction to avoid duplication.