underscore.js

Rails 4 - Conditional JS with dependent-fields-rails

左心房为你撑大大i 提交于 2019-12-10 12:50:41
问题 I'm trying to figure out how to use dependent-fields-rails gem with my Rails 4 app. I'm lost. I have included underscore.js in my vendor javascripts folder and updated my application.js to include (right at the bottom, just above require tree): //= require underscore //= require dependent-fields $(document).ready(function() { DependentFields.bind() }); In my simple form, I have: <%= f.input :has_milestones, as: :boolean, boolean_style: :inline, :label => 'Any decision points?', id: 'check

Deserialize query string to JSON object

别说谁变了你拦得住时间么 提交于 2019-12-10 12:47:08
问题 Tried to find how to make {foo:"bar"} from ?...&foo=bar&... but googled and got only to jQuery.params which does the opposite. Any suggestions please (built-in javascript function, jquery , underscore.js - all goes)? Or, do I need to implement it by myself (not a big hassle, just trying not to reinvent the wheel)? 回答1: You have Ben Alman's jQuery BBQ and a jQuery.deparam in it. It is described as The opposite of jQuery.param, pretty much. http://benalman.com/code/projects/jquery-bbq/examples

How do I escape EJS template code in node.js to be evaluated on the client side?

徘徊边缘 提交于 2019-12-10 11:15:22
问题 I use node.js/ejs on the server side and backbone.js on the client side. Both server side and client side use the same templating style. So the problem is, if I put template code meant for the client inside a template it still get's parsed on the server side. If found out that something like this works: <%- "<%= done ? 'done' : '' %\>" %> However, IMHO this uglifies the code in a way which makes the whole point of using templates useless. How would you approach this? Is there a way to define

How to re-create Underscore.js _.reduce method?

风流意气都作罢 提交于 2019-12-10 10:49:23
问题 For education purposes, I was trying to re-create Underscore.js's _.reduce() method. While I was able to do this in an explicit style using for loops. But this is far from ideal because it mutates the original list that was supplied as an argument, which is dangerous. I also realized that creating such method using functional programming style is harder, since it is not possible to explicitly set i value for looping. // Explicit style var reduce = function(list, iteratee, initial) { if (Array

Backbone js - Uncaught type error: Cannot read property 'on' of undefined

纵饮孤独 提交于 2019-12-10 10:44:44
问题 I have the following a very simple ToDo List app using Backbone framework. <!doctype html> <html> <head> <meta charset="utf-8"> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>To do List</title> <style> .completed{ text-decoration: line-through; color: #666; } </style> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script> <script type="text/javascript" src="js/underscore.js"></script> <script

What exactly does .apply do?

a 夏天 提交于 2019-12-10 10:33:39
问题 Never seen the .apply method before. Can someone explains to me what it does? This is taken from http://addyosmani.github.com/backbone-fundamentals/ var app = app || {}; var TodoList = Backbone.Collection.extend({ model: app.Todo, localStorage: new Backbone.LocalStorage(’todos-backbone’), completed: function() { return this.filter(function( todo ) { return todo.get(’completed’); }); }, remaining: function() { return this.without.apply( this, this.completed() ); }, nextOrder: function() { if (

how can i group JSON data into the weeks according to calender?

情到浓时终转凉″ 提交于 2019-12-10 10:28:10
问题 I am doing some d3JS programming to generate graph with JSON data. { "test": [ {"date":"1/5/2014","allocated":"14.14","unallocated":"7.14"}, {"date":"1/6/2014","allocated":"10.38","unallocated":"1.14"}, {"date":"1/7/2014","allocated":"1.43","unallocated":"3.14"}, {"date":"1/8/2014","allocated":"12","unallocated":"6.14"}, {"date":"1/9/2014","allocated":"13.34","unallocated":"4.44"}, {"date":"1/10/2014","allocated":"6.34","unallocated":"1.14"}, {"date":"1/11/2014","allocated":"8.34",

Binding and _.bindAll in backbone.js

烈酒焚心 提交于 2019-12-10 09:25:08
问题 I am confused about binding and the purpose of _bind.All in backbone.js. Below is a working code that creates a Modal view #modal and renders out comments fetched from the backend. Firstly, in the code below, I have in the initialize function _.bindAll(this, 'render', 'renderComments'); . Whether or not I do _.bindAll() , I have no problems calling this.render() and this.renderComments() inside initialize() . Are there any examples of when _.bindAll() will help us and when it will not?

Backbone collection: Retrieve distinct values of a collection

孤人 提交于 2019-12-10 08:46:49
问题 I have backbone collection of models and would like to retrieve the distinct values of a certain property If I have loaded data like the following into my collection: [{brand:'audi',id:'1234'}, {brand:'audi',id:'3456'}, {brand:'bmw',id:'3456'}] I would now want to get the distinct brands from the collection. The result should be: ['audi','bmw'] Looking at the Backbone and Underscore API I don't see anything obvious to achieve this. My current approach would be to use a library like jslinq Am

requirejs: Module name “underscore” has not been loaded yet for context [duplicate]

岁酱吖の 提交于 2019-12-10 08:17:56
问题 This question already has answers here : Trouble combining Require.js and Backbone.js/Underscore.js (3 answers) Closed 2 years ago . I always get this error when I freshly load my app, Error: Module name "underscore" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded ...,h){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.re... require.js (line 8) TypeError: Backbone.Model is undefined var ProjectModel = Backbone