当前位置:  开发笔记 > 编程语言 > 正文

mysql - 关于backbone+php的destroy问题

我通过重写backbonesync的destroy()来对应到php(点击删除按钮会触发delete事件),在php里实现对数据的删除,但是因为collection里定义了url,在重写destroy的url时,无法执行相应操作,求解答!{代码}{代
我通过重写backbone sync的destroy()来对应到php(点击删除按钮会触发delete事件),在php里实现对数据的删除,但是因为collection里定义了url,在重写destroy的url时,无法执行相应操作,求解答!

//Collection
App.Users=Backbone.Collection.extend({
  model : App.User,
  url : function(){
    return '/crud2/save.php';
  },
  initialize : function(){
    this.on('add',function(){
      console.log(this.length);
    });
    this.on('remove',function(){
      console.log(this.length);
    });
  }
});
  `delete : function(){
  //this.model.url='delete.php';
  //console.log(this.model.url);
  $('#Name').val("");
  $('#Phone').val("");
  this.model.destroy({
    url : 'delete.php',
    type : 'POST',
    success : function(){
      console.log('success');
    },
    error : function(){
      console.log('error');
    }
  }
  ); 
}`

//delete.php
username);
        $sql = "delete from user where username == '$data->username'";
        mysql_query($sql);
?>

回复内容:

我通过重写backbone sync的destroy()来对应到php(点击删除按钮会触发delete事件),在php里实现对数据的删除,但是因为collection里定义了url,在重写destroy的url时,无法执行相应操作,求解答!

//Collection
App.Users=Backbone.Collection.extend({
  model : App.User,
  url : function(){
    return '/crud2/save.php';
  },
  initialize : function(){
    this.on('add',function(){
      console.log(this.length);
    });
    this.on('remove',function(){
      console.log(this.length);
    });
  }
});
  `delete : function(){
  //this.model.url='delete.php';
  //console.log(this.model.url);
  $('#Name').val("");
  $('#Phone').val("");
  this.model.destroy({
    url : 'delete.php',
    type : 'POST',
    success : function(){
      console.log('success');
    },
    error : function(){
      console.log('error');
    }
  }
  ); 
}`

//delete.php
username);
        $sql = "delete from user where username == '$data->username'";
        mysql_query($sql);
?>
推荐阅读
女女的家_747
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有