Backbone.js Models and Collections Sync

I'm using Backbone.js with C# REST services, however we have separate endpoints for GETTING and POSTING data back to the server.

Using Backbone, how can we create our own unique save methods?


You need override Backbone.sync() .

You can do this globally for your application or specific to your model(s).

The best explanation and pattern I've seen comes from Addy Osmani's Developing Backbone.js Applications: http://addyosmani.github.io/backbone-fundamentals/#backbones-sync-api

The pattern is really nice because you define your persistence API elsewhere, and just assign the methods based on the request and method.

Also, here is really resourceful QA: How to override Backbone.sync?

Have a look at the Backbone.service plugin: https://github.com/mkuklis/backbone.service It allows your to include non-restful endpoints in your model.

链接地址: http://www.djcxy.com/p/67146.html

上一篇: 如果作为模型的属性传递,则不保存模型

下一篇: Backbone.js模型和集合同步