KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the best practice for passing bootstrapped variables within the rendered page (i.e. JSON data or config variables) to require.js so they can be checked for an used by dependancies? It looks like this could be done by checking the window object (i.e. window.bootstrapped_models but that does not seem very optimal. app.html - example data within the HTML document <script> var config = { "isAdmin": true, "userId": 1 }; var bootstrapped_models = { "groups": [ { "id": 1, "name": "Foo" }, { "id": 2, "name": "Bar" } ] } </script> app.js - example app using require() require(['jquery', 'GroupCollection'], function($, GroupCollection) { // extend default config if (config) { $.extend(defaults, config); } // use bootstrapped JSON here var collection = new GroupCollection; if (bootstrapped_models.groups.length > 0) { collection.add(bootstrapped_models.groups); } });
Tags (comma-separated)
Save Edits
Cancel