Search code examples
javascriptspine.js

Using Spine.Model.Ajax, how to handle extra properties in the responsed JSON when model updated


For example:

class User extends Spine.Controller
  @configure 'User', 'name'
  @extend Spine.Model.Ajax
  @url: '/save'

user = new User(name: 'test')
user.save()

User.bind 'update', (item) ->
  console.log(item.flag) # undefined

say '/save' response {flag: 0} because of some database error, when Ajax finished, Spine trigger the update event and update the user model, but there is no flag property extended to user when updated. So, how can I handle this situation when I need to response some extra data that is a little different from model?


Solution

  • After reading the document more carefully, I found the answer: see http://spinejs.com/docs/ajax [Custom serialization]