骨干js远程存储同步错误restful


Backbone js distant storage sync error restful

我尝试用主干js和PHP REFTful服务运行基本的CRUD操作。

然后我的web服务工作得很好,但我有骨干同步的麻烦,当我想删除没有JSON发送到我的web服务,但添加,更新我有JSON。

所以我不能用我的web服务删除,也许我有不好的方法去做。

这是代码:

app.js

$(function(){
    //MODELES
    window.Article = Backbone.Model.extend({
        defaults : {
            id : null,
            titre : null,
            contenu : null,
            image : null
        },
        initialize : function Doc() {
            console.log('Article Constructor');
            this.url = "index.php/article/article/id/"+this.id,
            this.bind("error", function(model, error){
                console.log( error );
            });
        },
        validate: function( attributes ){
            if( attributes.titre === '') {
                return "Titre ne peut pas être vide ";
            }
        }
    });
    //COLLECTIONS
    window.Articles = Backbone.Collection.extend({
        model : Article,
        url : "index.php/article",
        initialize : function() {
            console.log('Articles collection Constructor');
        }
    });
});

index . php

<!DOCTYPE HTML PUBLIC>
<html>
<head>
    <title>Main Page</title>
    <script src="<?php echo base_url();  ?>js/vendor/jquery-1.10.1.min.js"></script>
    <script src="<?php echo base_url();  ?>js/vendor/underscore-min.js"></script>
    <script src="<?php echo base_url();  ?>js/vendor/backbone-min.js"></script>
    <script src="<?php echo base_url();  ?>js/app.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
</body>
</html>

我正在铬控制台做我的测试。

listArticles = new Articles();
unArticle = new Article();
unArticle.set('titre','Le titre');
listArticles.add(unArticle);
unArticle.save(); //THAT WORKS
unArticle.destroy(); //DONT WORKS (SEND THE REQUEST BUT WITHOUT THE JSON, WITHOUT GET ID)

thanks in advance

Try this: Backbonejs with Restful services

这是一个关于Backbonejs和restful服务的很好的例子。