我的核心是,我需要了解表格提交或上述帖子中提到的投票申请中的最佳实践/正常方式.有没有人有一个很好的例子来证明一个看跌期权?
看看RFC
Several applications extending the Hypertext Transfer Protocol (HTTP)
require a feature to do partial resource modification. The existing
HTTP PUT method only allows a complete replacement of a document. This
proposal adds a new HTTP method,PATCH,to modify an existing HTTP
resource.
您将提供具有PUT和PATCH操作的id.你不会提供一个POST操作.
当我们加载我们的角形时,它通常采用两种方式之一.如果在我们创建新实体时加载表单,那么我们将没有id.我们将在控制器中知道这一点,并将调用resource.save.如果我们提供控制器加载表单,其中id用于从端点提取数据以填充表单,我们现在可以使用id来执行resource.update或resource.patch操作,具体取决于实体的数量我们正在更新.
这是一个处理更新和保存操作的示例保存功能.在这里,我们检查是否在我们进行资源调用之前通过路由提供了id.
angular.module('appModule').controller('ExampleCtrl',['$scope','$routeParams',function($scope,$routeParams) { $scope.saveForm = function () { //Do input validation before you make a resource call if ($routeParams.id) { //call resource update since we have an id } else { //call resource save since we don't have an id } }; }]);
这是angularjs文档中的示例:
如何创建自定义PUT请求:
var app = angular.module('app',['ngResource','ngRoute']); // Some APIs expect a PUT request in the format URL/object/ID // Here we are creating an 'update' method app.factory('Notes',['$resource',function($resource) { return $resource('/notes/:id',null,{ 'update': { method:'PUT' } }); }]); // In our controller we get the ID from the URL using ngRoute and $routeParams // We pass in $routeParams and our Notes factory along with $scope app.controller('NotesCtrl','Notes',$routeParams,Notes) { // First get a note object from the factory var note = Notes.get({ id:$routeParams.id }); $id = note.id; // Now call update passing in the ID first then the object you are updating Notes.update({ id:$id },note); // This will PUT /notes/ID with the note object in the request payload }]);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。