by littlejim84 · 14y ago · 0 comments
myApp.init = function() {
Books.fetch();
Authors.fetch();
Notes.fetch();
...
};
... is because, all else being equal, it will noticeably improve the speed of your initial page load. Instead of N separate HTTP requests, all of your model data is available in the same HTTP request that fetches the HTML. Put the bootstrap at the bottom of your page, and you're in pretty good shape. from dynamicresponse.emitters import JSONEmitter
@register.filter
def serialize_to_json(obj):
emitter = JSONEmitter(obj, {}, None)
return emitter.render()
In the template script tag: var myObj = new MyObject({{python_object|serialize_to_json}});
var myObjView = new MyObjectView({ model: myObj });
It then renders just as if you loaded it via an api call.If you feel weird about loading data as a js file, there is also a requirejs plugin for loading raw json files as a module: https://github.com/millermedeiros/requirejs-plugins
1. Initialize views without models, hidden.
2. Make your 'top-level' view bind to a collections 'reset' event that fires once the model is loaded. At that stage you can give instances of the loaded models to whatever views need them and they can redraw themselves, either by calling a method on them directly or because they're listening for some event that you trigger.