2011-12-22 28 views
1

我在計算Backbone + Coffeescript中的model.save語法時遇到了問題。 (Rails 3中)語法Backbone model.save

我有以下幾點:在這種情況下

@options.product_search.save({'url' : $("#product_search").val()}, 
    {success: (event) => alert "StackOverflow"}, 
    {error: (response) => alert "oh no!"} 
) 
  1. 成功事件的作品,錯誤事件不會。
  2. 我也不知道如何將多個動作添加到成功事件中,因爲當我將代碼拆分爲成功事件中的多行時,coffeescript會給我一個語法錯誤。

謝謝你的幫忙! 最佳,菲爾

回答

0

你投入第三個參數爲保存方法,它只能有兩個:

model.save([attributes], [options]) 

這僅僅是一個CoffeeScript的/ JavaScript語法錯誤很容易修復。

試試這個:

@options.product_search.save 
    url: $("#product_search").val() 
, 
    success: (model, response) -> 
    alert "StackOverflow" 
    alert "More alerts" 

    error: (model, response) -> 
    alert "oh no!" 
+0

必須在骨幹文檔跳過語法!非常感謝@joshvermaire,作品的魅力! – user966041

相關問題