Skip to content

Instantly share code, notes, and snippets.

@molekilla
Created March 29, 2012 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molekilla/2243990 to your computer and use it in GitHub Desktop.
Save molekilla/2243990 to your computer and use it in GitHub Desktop.
Escuelita de Scala - Parte 5 - Backbone MVC Typeahead
// application.js
var App = {
Views: {},
Controllers: {},
Collections: {},
init: function() {
new App.Controllers.TypeaheadItems();
Backbone.history.start();
}
};
// controllers/typeahead.js
App.Controllers.TypeaheadItems = Backbone.Router.extend({
routes: {
"": "index",
},
index: function() {
new App.Views.Index({ items: new App.Collections.TypeaheadItems() });
}
});
// models/typeahead.js
var TypeAheadItem = Backbone.Model.extend({
initialize: function(){
}
});
App.Collections.TypeaheadItems = Backbone.Collection.extend({
model: TypeAheadItem,
value: null,
url: function() {
return "/typeahead/" + this.value;
},
toArray: function() {
return _(this.models).map( function (i) { return i.get("item"); } );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment