我正在尝试这个,但有一个jQuery错误
$(location).attr("href",'/imageblocks/'+$(el).attr('id')+'/edit/')
Run Code Online (Sandbox Code Playgroud)
它在JavaScript上完美运行,但是用CoffeScript触发了jQuery错误,我猜它是$(位置)但找不到正确的单词.
我开始使用nodejs这是一个很棒的工具.我用它来开发我的前端,我已经使用coffee-script自动编译为javascript,以及允许我编写单元测试的jasmine包.我正在寻找很酷的软件包来加速我的javascript/css developppement.
例如,当我完成开发我的应用程序时,我想要一个缩小所有javascript文件的包,然后把它放在一个文件中,有点像闭包编译器.我想我必须写一些清单文件,然后一个nodejs utiliy将采取该清单中列出的所有文件并"编译"我的应用程序.
那么nodejs包可以做什么呢?
我还应该使用javascript/coffeescript进行快速前端开发吗?谢谢.
当我尝试在咖啡脚本中编写多个构造函数时,我得到了这个错误:cannot define more than one constructor in a class.
我怎样才能做到这一点:
class Vector2
x: 0
y: 0
constructor:() ->
constructor:(@x, @y) ->
constructor:(vector) ->
x = vector.x
y = vector.y
Run Code Online (Sandbox Code Playgroud)
我想要一个空的构造函数和另外两个构造函数.这可能吗?
有没有一种优雅的方法来异步映射coffeescript中的对象或数组?(或者javascript.)
想象一下,我在对象中有一些东西:
things =
x:
...
y:
...
z:
...
thingCount = 3
Run Code Online (Sandbox Code Playgroud)
我想创建一个方法来处理这些事情并返回处理过的对象.该过程必须进行异步调用以获取有关每个事物的一些信息.起初我试图像这样循环遍历属性:
processThings = (callback) ->
processedThings = {}
count = 0
for key,val in things
asyncJob key,val (err,result) ->
if err
callback error
else
# PROBLEM: key has the incorrect value here
processedThings[key] = result
count += 1
if count == thingCount
callback null,processedThings
Run Code Online (Sandbox Code Playgroud)
问题是键的值在循环中发生了变化.所以我的解决方案是创建一个子函数,以便键变量包含在其闭包中:
processThings = (callback) ->
processedThings = {}
count = 0
processThing = (key,val) ->
asyncJob key,val (err,result) ->
if err
callback error …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 3.1,似乎我在我的create_error.js.coffee视图文件中的CoffeeScript语句之后无法使用Ruby脚本来获取AJAX响应.
如果我这样做它会起作用:
<% if @attached_image.errors.any? %>
alert 'something is wrong'
<% end %>
Run Code Online (Sandbox Code Playgroud)
但如果它如下所示,<% %>在CoffeeScript语句之后,
errors_block = '<div id="errors_block"></div>'
<% if @attached_image.errors.any? %>
something..
<% end %>
Run Code Online (Sandbox Code Playgroud)
我总是支持得到一个异常ActionView::Template::Error (Parse error on line 6: Unexpected 'INDENT')的if线.我已经尝试了几个样本,每当它发生<% %>在一个coffeescript声明之后的红宝石时.
这是为什么?
我不是在每个匹配值上调用一个函数,而是想获取值数组['broccoli', 'spinach'],但我不断遇到编译器错误.有人能解释一下我的误解吗?
# Health conscious meal. - This example is from http://coffeescript.org/#loops
foods = ['broccoli', 'spinach', 'chocolate']
eat food for food in foods when food isnt 'chocolate'
# Failed Attempt #1 - Unexpected TERMINATOR
arr = for food in foods when food isnt 'chocolate'
# Failed Attempt #2 - Unexpected ')'
arr = (for food in foods when food isnt 'chocolate')
Run Code Online (Sandbox Code Playgroud) 我正在关注Rails演员来实现订阅计费.它在这里:
http://railscasts.com/episodes/288-billing-with-stripe
我的代码几乎完全相同,但我将一些额外的字段传递给Stripe.麻烦的是,javascript中的错误消息总是在提交按钮被点击时显示错误消息...即使成功收费.我不确定Strip是否返回了触发错误的东西,或者是否存在JS问题.
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subscription.setupForm()
subscription =
setupForm: ->
$('#new_membership').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
subscription.processCard()
false
else
true
processCard: ->
card =
number: $('#card_number').val()
cvc: $('#card_code').val()
expMonth: $('#card_month').val()
expYear: $('#card_year').val()
Stripe.createToken(card, subscription.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#membership_stripe_card_token').val(response.id)
$('#new_membership')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
Run Code Online (Sandbox Code Playgroud)
这是用于错误处理的示例条带.他们首先翻转过程并测试错误:
function stripeResponseHandler(status, response) {
if (response.error) {
...
//show the errors on the form
$(".payment-errors").html(response.error.message);
} else {
var form$ = $("#payment-form");
// token contains id, last4, and card type …Run Code Online (Sandbox Code Playgroud) 关于如何将其写为coffeescript的任何想法?
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');
return firstName + ' ' + lastName;
}.property('firstName', 'lastName')
});
Run Code Online (Sandbox Code Playgroud)
我}.property对代码的一部分特别感兴趣.我无法弄清楚如何在coffeescript中写这个.
我刚刚实现了一个连接到MongoDB数据库并生成报告(PDF)的JSF(Web JavaScript应用程序),这要归功于JasperReports Library(所以使用.java文件).
是否可以使用CoffeeScript和Node.js中的Web应用程序执行相同的操作?我真的很陌生,所以我不知道从哪里开始.
例如:由于Node.js或CoffeeScript,是否可以运行.java?
我试图将以下语句从Coffeescript重写为Javascript:
d.data.name[0..1].toLowerCase()
有人可以告诉我这句话是什么意思吗?
coffeescript ×10
javascript ×5
node.js ×3
actionview ×1
ember.js ×1
erb ×1
jasmine ×1
jquery ×1
mongodb ×1