Backbone.js的保存的CoffeeScript [英] backbone.js save with coffeescript

查看:109
本文介绍了Backbone.js的保存的CoffeeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CoffeeScript中定义的骨干视图下面的方法:

I have the following method on a backbone view defined in coffeescript:

  saveObservation: =>
    self = @
    observation = new Observation(ParentUid: _questionUid, Status: "N/a", Text: "Change to element")
    observation.save {
          success: ->
            alert('test')
          error: ->
            alert('failed')
        }

观察从Backbone.Model延长

Observation is extended from Backbone.Model

class Observation extends Backbone.Model
  url: ->
    "/AuditActionTracking/"  

在保存到达服务器,但Ajax调用完成后,无论是成功的还是我在保存中定义的错误处理程序获取调用。

The save reaches the server but neither the success nor the error handlers I have defined in the save are getting called after the ajax call has completed.

有人能看到我在做什么错了?

Can anyone see what I am doing wrong?

推荐答案

Backbone.Model.save 需要 2 的参数,第一个是你改变属性的列表,第二是回调的配置。

Backbone.Model.save takes 2 parameters, the first is a list of properties you're changing, and the second is the callback configuration.

所以,如果你不改变保存过程中的任何其他属性,你可以传递一个空的对象:

So, if you're not changing any other properties during save, you can just pass an empty object:

observation.save {},
    success: (model, response) ->
      alert('test')
    error: (model, response) ->
      alert('failed')

这篇关于Backbone.js的保存的CoffeeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆