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

Nested Model #231

Open
gabrielp16 opened this issue Jan 6, 2017 · 3 comments
Open

Nested Model #231

gabrielp16 opened this issue Jan 6, 2017 · 3 comments

Comments

@gabrielp16
Copy link

gabrielp16 commented Jan 6, 2017

Hi,

I have a problem with a nested model:
{
name:'Gabo',
scheduler:{
date: 1987198712,
type: 'daily'
}
}
the modelBind doesn't recognize the properties in scheduler, how can I do for make a bind in date and type?

Thank you for your attention

@amakhrov
Copy link
Contributor

amakhrov commented Jan 6, 2017

@gabrielp16 I assume you're talking about the scheduler attribute.
Is it a real nested model (an instance of BB.Model with attributes date and type) or just a plain object (POJO)?

@gabrielp16
Copy link
Author

Is a a plain object (POJO)... that change the point of view?

@amakhrov
Copy link
Contributor

amakhrov commented Jan 6, 2017

In this case you can use converters, like that:

binder.bind(model, el, {
  scheduler: [
    {
      selector: '.date',
      converter: (dir, value) => {
        if (dir === ModelBinder.Constants.ModelToView) return value.date;
        else return Object.assign({}, model.get('scheduler'), {date: value});
      }
    },
    // ... and a similar binding for "type"
  ],
});

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

2 participants