Skip to content

Instantly share code, notes, and snippets.

@maletor
Created July 23, 2012 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maletor/3162378 to your computer and use it in GitHub Desktop.
Save maletor/3162378 to your computer and use it in GitHub Desktop.
Bootstrap data using RequireJS and Backbone
require(['userAttributes', 'backbone', 'user_router'], function (config, Backbone, UserRouter) {
var userRouter = new UserRouter() {
userAttributes: userAttributes
};
return router;
});
<!doctype html>
<html lang="en">
<head>
<title>Page</title>
<script data-main="app" src="require.js"></script>
<script>
require('userAttributes', function() {
return {
val1: 'hello',
val2: 'world'
};
});
require('colleagues', function() {
return {
val1: 'memcache',
val2: 'is your friend'
};
});
require('publications', function() {
return {
val1: 'memcache',
val2: 'is your friend'
};
});
</script>
</head>
<body>
</body>
</html>
define(['backbone', 'view'], function(Backbone, View) {
var view = Backbone.Router.extend({
routes: {
'*index': 'index'
},
index: function() {
new View({
first: userAttributes.val1,
second: userAttributes.val2
}).render();
}
});
return view;
});
define(['backbone'], function(Backbone) {
var view = Backbone.View.extend({
render: function() {
console.log(this.first + ', ' + this.second);
}
});
return view;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment