Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple change to provide more flexibility for attributes #62

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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