Using bootstrap-modal as Backbone.js view

Allright, so the solution is was rather simple: App.Views.ProjectsNav ||= {} class App.Views.ProjectsNav.NewProjectView extends Backbone.View tagName: ‘div’ events: { ‘click .save’: ‘save’, ‘click .cancel’: ‘hide’, ‘hidden’: ‘hidden’, ‘shown’: ‘shown’ } initialize: (options) -> super(options) @collection = options.collection hide: () -> @el.modal(true).hide() false save: (e) -> … @model.save(attrs, { success: (project) => @model = project @collection.add(@model) … Read more

Backbone.js – Given an element, how do I get the view?

I’ve just written a jQuery plugin for this. It also uses the .data() method. Registration: I have wrapped / proxied the Backbone View setElement method to attach the required data to the view’s $el property. Registration is done behind the scenes like so: $(myViewsEl).backboneView(myView); Retrieval: The plugin traverses up the DOM hierarchy (using .closest()) until … Read more

Backbone.js: complex views combining multiple models

In that case, I’d consider a dynamic model with both of your sub-models. In your route handler, you could do something like this: var model = new Backbone.Model(); model.set({contacts: new ContactsModel(), users: new UsersModel()}); var view = new GridView({model: model}); Of course, there is nothing stopping you from passing in the models separately: var contacts … Read more

Cannot call ‘start’ of undefined when starting backbone.js history.

Do you have any routes on the controller? Backbone only creates the history once at least one route is specified. More: TypeError: Cannot call method ‘start’ of undefined** Hmm, for some reason Backbone.history is undefined, and so there is no start method on it. It turns out that Backbone.js creates an instance of Backbone.History (upper … Read more

handling backbone model/collection changes in react.js

Instead of manually binding event listeners, you can use a mixin based on this BackboneMixin to help automatically bind and unbind the listeners: https://github.com/facebook/react/blob/1be9a9e/examples/todomvc-backbone/js/app.js#L148-L171 Then you simply write var List = React.createClass({ mixins: [BackboneMixin], getBackboneModels: function() { return [this.props.myCollection]; }, render: function(){ var listItems = this.props.myCollection.map(function(item){ return <li>{item.get(“someAttr”)}</li>; }); return <ul>{listItems}</ul>; } }); and the … Read more

Yeoman Workflow and Integration with Backend Scripts

I like using this structure: rails-app/ –app/ –views/ –js/ –app/ –test/ –Gruntfile.js –public Here’s how I set it up: rails new rails-app cd rails-app/app/views mkdir js cd js yeoman init ember Then edit Gruntfile.js to change “output: ‘dist’” to “output: ‘../../../public’” After that, “yeoman build” or “yeoman build:dist” will output to the Rails /public folder. … Read more

Backbone.js: communication between views

I wrote up an article a while back on a few different options for coordinating between views: http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/ in your case, i’d recommend using the event aggregator that i describe in that article. you could have each item view listen for a “editmode” event, or something similar. when this event fires, each view that listened … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)