Skip to content

Conversation

@tobowers
Copy link

@tobowers tobowers commented Feb 7, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants