Created
November 18, 2012 11:59
-
-
Save odiroot/4104798 to your computer and use it in GitHub Desktop.
Backbone.js post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyLayout = Backbone.View.extend({ | |
subViews: [Foo, Bar], // This can be modified in runtime. | |
render: function() { | |
_.each(this.subViews, function(V) { | |
var widget = new V().render(); | |
this.$el.append(widget.$el); | |
}, this); | |
return this; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var top = new MyTopView({ | |
el: "#top-view" | |
}); | |
var middle = new MyMiddleView({ | |
el: "#middle-view" | |
}); | |
var bottom = new MyBottomView({ | |
el: "#bottom-view" | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main JS file. | |
require([app], function(App) { | |
var app = new App(); | |
app.start(); // Initialize and run application. | |
}); | |
// app.js | |
define([myview], function(MyView) { | |
var App = function(){}; | |
App.prototype.start = function() { | |
this.view = new MyView({ | |
el: "body" | |
}).render(); | |
}); | |
return App; | |
}); | |
// myview.js | |
define(["backbone"], function(Backbone) { | |
return Backbone.View.extend({ | |
foo: "bar" | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyModel = Backbone.Model.extend({ | |
foo: "bar" | |
}); | |
var MyCollection = Backbone.Collection.extend({ | |
model: MyModel | |
}); | |
// App initialization... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bootstrapping file. | |
ProjectFoo = this.ProjectFoo || {}; | |
ProjectFoo.Models = ProjectFoo.Models || {}; | |
ProjectFoo.Views = ProjectFoo.Views || {}; | |
// Views file. | |
ProjectFoo.Views.MyView = Backbone.View.extend({ | |
// [..] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment