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

Access nested model attribute #2

Closed
pheuter opened this issue Sep 18, 2012 · 9 comments
Closed

Access nested model attribute #2

pheuter opened this issue Sep 18, 2012 · 9 comments

Comments

@pheuter
Copy link

pheuter commented Sep 18, 2012

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
Copy link
Member

delambo commented Sep 18, 2012

@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
Copy link
Author

pheuter commented Sep 18, 2012

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

@delambo
Copy link
Member

delambo commented Sep 19, 2012

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

@delambo delambo closed this as completed Sep 19, 2012
@nilaysaha
Copy link

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
Copy link

mehcode commented Nov 8, 2013

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
Copy link

Hi Ryan,
Question is whether i can set the model value once the view is updated.
As i understand stickit calls model.set function and the format of that
function is different when backbone nested is used for example.
So my model is not updated when view element is changed,

Regards,
Nilay

On Friday, November 8, 2013, Ryan Leckey wrote:

Not sure I understand, @nilaysaha https://github.com/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?


Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-28032552
.

@mehcode
Copy link

mehcode commented Nov 8, 2013

Can I see the code for your bindings?

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

@nilaysaha
Copy link

here they are:

           bindings:{
               '#redemption_budget':{
                   modelAttr: 'budget.total_redemption_budget',
                   observe:'budget',
                   onGet: function(val){return

parseFloat(val.max_num_redemption)*parseFloat(val.value_per_redemption)},
}
},

so as you see the nested model attributes are compatible with model nested
and setting a value of attr, we would do :
this.model.set({'budget.total_redemption_budget':10}) for example.

regards,
Nilay.

On Fri, Nov 8, 2013 at 8:48 AM, Ryan Leckey notifications@github.comwrote:

Can I see the code for your bindings?

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


Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-28043398
.

@Fiveside
Copy link

Fiveside commented Nov 8, 2013

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants