Tag: backbone.js

How do I union/merge two Collections by their 'id' using UnderscoreJS

I have two collections (Menu and Orders) Menu collection contains array of Item objects [{‘id’: ‘1’, ‘name’: ‘apple’}, {‘id’: ‘2’, ‘name’: ‘orange’}] And Orders collection also contains array of Item objects [{‘id’: ‘1’, ‘quantity’: ‘0’}] And I want them merged together their attributes by ID into another collection (this is needed for templating purposes only): […]

Backbone router on every route

My problem is: All the HTML is in a <div id=”application”> container, which by default has 0 opacity. This is because JavaScript does some DOM positioning, so when this is all done I just add a class=”rendered” into the <div id=”application>” and then the page appears. So the thing is, for every route in my […]

Backbone.js pushState is not working and gives a 404 error

I have been watching the screencast from PeepCode on Backbone.js, and have done the coding with it. I have finished the first part and now, I have a Router like this: routes: { ”: ‘home’, ‘blank’: ‘blank’ } and also I have this to start the App: $(function(){ window.App = new BackboneTunes(); Backbone.history.start({pushState: true}); }); […]

how can i print the row line in BackboneJS *marionette* collectionView?

I have a collectionView that creates a UL using a LI itemView. I wanted to use the item index number (count) in the underscore template. i.e.: hello (item 0) world (item 1) Does anybody know how to use the count in marionette? i want to avoid putting it in the model. this is what i […]

Click Event in 'Backbone.js View' do not work

I tried to start to work with backbone.js, but I found the Event does not work when I do NOT use ‘body’ as the View’s el. Here is the code. You can save it as a html file and run it. <html> <body> <button id=’openEssay’>test</button> <div id=’div’ style=’width:100px;height:100px;’></div><script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js”></script> <script src=”http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js”></script> <script src=”http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js”></script><script> (function($){ var […]

Unable to test debounced Backbone view event

When I am not throttling/debouncing the function the test passes. However when I debounce the event to prevent flooding the server the test no longer passes. Mocha outputs AssertionError: expected execute to have been called at least once, but it was never called It should be noted that the debounced call works without errors in […]

breaking out of an underscore each

I am trying to find a model within a collection with an attribute equal to html select option value. <div id=”hospital-details”> <select name=”hospitalnames”> <option><%- model.get(‘name’) %></option> </select> </div> whenever hospital name is changed, jquery change callback is triggered to find locationModel with selected option value as attribute value as shown below, $(‘select[name=”hospitalnames”]’).change(function() { var name […]

Binding events conditionally in Backbone – mobile or desktop

To make it easier to read i put everything under the initialize function. Is there something wrong here? The alert gets triggered so it’s not the condition. I have the share actions hidden and would like to show them on Hover on desktop and Tap on mobile given the hover impossibility. Am I missing something […]

Trouble combining Require.js and Backbone.js/Underscore.js

I’ve read previous threads where other members have had identical error messages as me, but their accepted solution doesn’t seem to help. Basically I get this in Chrome console when I try to load index.html: Uncaught Error: Module name “underscore” has not been loaded yet for context: _. Use require([]) A couple of seconds later […]

Detect when a view is removed from the page using Backbone.js or Marionette.js

using Backbone.js with Marionette.js (Go Derick Bailey!). Need to detect when a view is removed from the page. Specifically, I’m overwriting it with another view. Is there an event I can detect of function I can overload to detect when this happens? Thanks!