EDIT of the EDIT:
model = new Model({_id:id})
var fetched = model.fetch();
// wait for the model to be fetched
$.when(fetched).then(function(){
view = new View({model:model})
app.content.show(view)
});
from https://stackoverflow.com/a/13601074/2535516
EDIT :
This refers about the comment. About building code, i think u refer as organization of a backbone project (correct me if i'm wrong). If so, the way i am doing is write my code by module. A module is basically : a BackboneModel/Collection, View, and underscore template.
Architecture :
/
main.js
About/
-- about.html <-- contains the underscore template
-- aboutView.js
-- aboutModel.js
-- aboutCollection.js
Menu/
-- menu.html
-- menuView.js
-- menuModel.js
-- menuCollection.js
And i load it through an AMD lib, mostly require.js
This architecture is a personal, what you will mostly see is :
/
main.js
View/
-- about.js
-- menu.js
Model/
-- aboutModel.js
-- menuModel.js
Collection/
-- aboutCollection.js
-- menuCollection.js
A good example is the TODOMvc architecture
Your code will work, but this is not very readable and will go worse if you'll have to add some fetch :
HomeText.fetch({
AboutText.fetch({
Module1Text.fetch({
Module2Text.fetch({
});
});
});
});
This is call the pyramid of doom. To avoid this, use promises.
As a note, jquery do promises