creating a model structure in backbone

2020-03-31 08:42发布

问题:

I need to create a model having a structure like this:

name: 'xyz',
relatives: [ {name:'abc',age:'123'},{name:'def',age:'123'}..... ]

What i have is a loop which in each iteration generates data for relatives. And i have a model in this state like:

window.Persons.name='xyz'

TWO QUESTIONS

  1. How to push relatives data in this model? I need to understand that how one can construct model instances having nested objects structures to any level?

  2. I am setting the context of model to the window object so that its accessible in all the views as i collect data from different views. Like name is collected in some other view and relatives in some other view and this goes on....So am i doing the right thing? Or i am polluting the global namespace.

Please shed some light as i am sure i am lacking some fundamental understanding here.