backbone.modelbinding
backbone.modelbinding copied to clipboard
Simple change to provide more flexibility for attributes
This is a simple change that could be the start of something larger. I had seen others talking about rails integration and the object[attr] names there. Rather than a major refactor, this small fix allowed me to monkey patch by overriding Configuration.getBindingValue as so:
Backbone.ModelBinding.Configuration.prototype.getBindingValue = (element, type) ->
bindingAttr = this.getBindingAttr(type)
# looks for the railsish object[attribute] style
attributeRegex = /^[^\[]+\[(.+)\]$/
attributeValue = element.attr(bindingAttr)
if attributeRegex.test(attributeValue)
return attributeValue.match(attributeRegex)[1]
else
return attributeValue
To be clear: the above change is not in my commit - just changing where functions are assigned. It should save a little memory on every config instance too.