coffeescript

Sort and merge JSON keys with matching values

半腔热情 提交于 2019-12-31 03:52:06
问题 My JSON looks like this: json = [ { type: "big" date: "2012-12-08" qty: 6 } { type: "small" date: "2012-12-08" qty: 9 } { type: "big" date: "2012-12-15" qty: 4 } { type: "small" date: "2012-12-07" qty: 7 } { type: "small" date: "2012-11-07" qty: 3 } ] What I'm trying to do is group/merge each type that has a date with the same year & month (the first 7 characters in the date string) and get the sum of those qty 's. The output should look like this: json = [ { type: "big" date: "2012-12" qty:

Data is not getting updated in the view after promise is resolved

爱⌒轻易说出口 提交于 2019-12-31 03:18:08
问题 I am using my Rails app as an API backend. So I have a single page angular app which will make multiple api calls and start displaying as each data gets returned. I don't want to wait for all the results from the API call and then load the data, so I started learning deferred and promise. I have an angular service called api where I will have $http calls to all my api. I have hardcoded the data that returns from each one of the api calls for testing purposes. debugger.factory "api", ["

Ordinals in words javascript

冷暖自知 提交于 2019-12-31 01:57:22
问题 Is there any elegant way how to get ordinals in word format in js/coffee? Something like this: ordinalInWord(1) # => "first" ordinalInWord(2) # => "second" ordinalInWord(5) # => "fifth" 回答1: I'm afraid the ordinals aren't regular enough to avoid typing each of them out. function ordinalInWord( cardinal ) { var ordinals = [ 'zeroth', 'first', 'second', 'third' /* and so on */ ]; return ordinals[ cardinal ]; } If you need the function work past 20, you can take advantage of the pattern that

Using Karma-runner with AngularJS, Jasmine, CoffeScript

巧了我就是萌 提交于 2019-12-31 01:56:15
问题 My app besides jRuby/Rails uses AngularJS , CoffeScript . I'd like to test my javascript with Jasmine and run it with Karma (aka Testacular ), but I get an error stating that my Angular module is nowhere defined . What I've got: installed Node.js and Karma , generated a config file: // base path, that will be used to resolve files and exclude basePath = '../'; // list of files / patterns to load in the browser files = [ JASMINE, JASMINE_ADAPTER, 'vendor/assets/javascripts/angular.js', 'vendor

Syntax error when deploying Rails app to Heroku: ExecJS::RuntimeError: SyntaxError: Unexpected character

坚强是说给别人听的谎言 提交于 2019-12-31 01:47:09
问题 I am trying to deploy my app to Heroku but its throwing me this error. "ExecJS::RuntimeError: SyntaxError: Unexpected character '`' (line: 14577, col: 33, pos: 440811" I assume there is something wrong with the coffeescript/javascript. I have deleted all of my coffeescript files and I dont know what I'm doing wrong. As suggested by Iceman, ive tried running the command rake assets:precompile RAILS_ENV=development and it says I, [2017-01-26T16:32:25.173928 #2674] INFO -- : Writing >/Users/Gana

Using jQuery.Deferred to avoid nested setTimeout callbacks

南笙酒味 提交于 2019-12-30 22:59:48
问题 setTimeout -> console.log 'foo' setTimeout -> console.log 'bar' setTimeout -> console.log 'baz' , 1000 , 1000 , 1000 Is it possible to achieve the same result with jQuery.Deferred? Something like the following, perhaps: someFunction() .then(-> console.log 'foo') .then(delay 1000) .then(-> console.log 'bar') .then(delay 1000) .then(-> console.log 'baz') Perhaps I'm wrong in thinking promises make it easy to write: Do A, then once that finishes, do B, then once that finishes, do C . 回答1: You

资深web前端工程师总结出一套正确的学习思路

北慕城南 提交于 2019-12-30 15:29:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 对于零基础的学员来说:初接触一门技术,想要去了解他,并掌握它,是不是觉得有点无从下手,不知道该学习什么?该先学哪个后学哪个? 今天一位资深web前端工程师,用他多年从事web前端工作的个人经验总结出一套正确的学习思路,分享给你们! 具体来说,前端方面的知识从重要程度来排,应该先后学这些: 第一步学习基础知识 api学习,系统地学,可以看看这个方面的书,不要只零散地看网上文章,这个书钱要舍得花。前端领域,这个方面我推荐看看《javascript高级程序设计》和《html5和css3权威指南》。 第二步学习一些编程技巧 学习一些编程上的技巧,比如面向对象,组件,api设计,推荐几本书《js设计模式》《head first设计模式》和《代码整洁之道》。 第三步学习一些框架 学习除jqury之外的一两个框架,因为jqury只是个库,算不上框架,加上jqury ui也仍然只是个库。学学两个前端框架,再学一个后端框架,加强对所谓框架的理解,回头再来做框架选型,就可以有自己的理解和态度了,而不是跟风。 第四步学习一些编程工具 然后学的是工具类的,比如预处理器,打包工具,调试工具,开发工具啥的,less,sass,coffeescript,grunt,git,vim之流,晚点学不会死,甚至不学也不见得有啥问题,这种工具类的

CoffeeScript always returns in anonymous function

旧时模样 提交于 2019-12-30 10:05:06
问题 I'm trying to write some CoffeScript function which checks all checkboxes in a table upon checking the checkbox in the th. My function in CoffeeScript looks like this: $("table.tableview th input:checkbox").live 'click', -> checkedStatus = this.checked $("table.tableview tbody tr td:first-child input:checkbox").each -> this.checked = checkedStatus It works great for checking all the boxes. However when unchecking it doesn't work. The compiled JS looks like this: $("table.tableview th input

AngularJS Error: Unknown provider: aProvider <- a

给你一囗甜甜゛ 提交于 2019-12-30 02:48:57
问题 OK I'm officially bald now, after having been streching my hair out with this infamous problem: The minfied AngularJS app just doesn't work, with this error thown out: Error: [$injector:unpr] Unknown provider: aProvider <- a http://errors.angularjs.org/1.2.6/$injector/unpr?p0=aProvider%20%3C-%20a at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:11492 at http://localhost/my-app/dist/scripts/1bde0e2e.vendor.js:4:26946 at Object.c [as get] (http://localhost/my-app/dist/scripts

What needs to be configured for Heroku to handle templates based on CoffeeScript?

戏子无情 提交于 2019-12-30 01:58:04
问题 I have a create action that handles an AJAX request. On my development machine, a template named create.js.coffee is successfully processed to generate a javascript response. However, when I deploy to Heroku, the application complains that it can't find the template. ActionView::MissingTemplate (Missing template /expenses/create with {:handlers=>[:erb, :builder], :formats=>[:js, :html], :locale=>[:en, :en]}. Searched in: * "/app/app/views" * "/app" * "/" ): It's clear that the coffee handler