Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Access nested model attribute #2

Closed
pheuter opened this Issue · 9 comments

5 participants

@pheuter

It doesn't seem possible to bind a nested model attribute to a dom element.

For example:

bindings:
    '#title':
      modelAttr: 'model_data.client.name'
@delambo
Owner

@pheuter I think you can manage to walk that attribute in the format callback before it is updated to the view element:

bindings: {
  '#title': {
    modelAttr: 'model_data',
    format: 'formatTitle'
  }
},
formatTitle: function(val) {
  return val.client.name;
}

Does this work out for you?

@pheuter

@delambo I just went with Backbone.Deep-Model, and so when stickit calls model.get() on modelAttr, it returns the nested attribute.

@delambo
Owner

@pheuter Thanks for the update - glad to hear that stickit works well with deep-model.

@delambo delambo closed this
@nilaysaha

no the reverse does not work on nested model. I am using backbone-nested. And the set command is asymmetric with backbone.

In backbone set is: this.model.set('attr',value). Whereas in backbone-nested or in backbone-deep-model set is : this.model.set({'attr':value}). So how do I overcome this... ?

thanks for the great module anyway...

@mehcode

Not sure I understand, @nilaysaha

In backbone, this.model.set('name', value) is identical in operation to this.model.set({'name': value}) -- the same change events should be raised that stickit checks for, etc.

What sort of problems are you seeing?

@nilaysaha
@mehcode

Can I see the code for your bindings?

Keep in mind modelAttr has changed to observe since this issue (from a year ago).

@nilaysaha
@CactusCommander

Hi @nilaysaha ,

Keep in mind modelAttr has changed to observe since this issue (from a year ago).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.