I'm just getting started with backbone, and I have run into a very confusing wall.
What I am doing:
- Create a model instance of type A that calls fetch during initialization.
- Create a model instance of type B that calls fetch during initialization.
- Create a view that uses data from both.
- Bind the sync event from both of the models to view.render(), and create a table once both AJAX calls have returned (render will be called twice, I know - not a big deal).
What I am expecting is that when the second sync event hits, the table is rendered using data from both.
What is actually happening is that the sync event is firing, but the model data is completely empty when the view tries to use it (I can check the model.cid and see that it is the same model that I created initially, it just contains absolutely nothing). I have logging so that I can tell which event is firing from which model, and I can see render being called twice as expected.
I can add a debug button to my page that calls the same render manually (once both AJAX calls have completed), and everything renders just fine, so I know both my AJAX calls were ultimately successful and did eventually result in a fully populated model.
What am I doing wrong? Am I fundamentally misunderstanding what an event is supposed to do here? Why would my model be completely empty after a sync event?
Dave