例如,以a RESTful CRUD SPA with angularjs为例。Angularjs JavaScript在CRUD SPA中使用PUT时速度更快
在Angularjs中使用RESTful方法时,我遇到了update/delete/etc等情况。没有进行硬刷新(F5)不会反映在列表中。这是因为保存/更新/删除花费的时间超过了JavaScript运行下一个应更新列表的命令。
app.controller('UserDetailCtrl', ['$scope', '$routeParams', 'UserFactory', '$location',
function ($scope, $routeParams, UserFactory, $location) {
// callback for ng-click 'updateUser':
$scope.updateUser = function() {
UserFactory.update($scope.user); // Before this is done
$location.path('/user-list'); // this has already fetched the (outdated) list
};
来自例如, .NET MVC在这样的情况下,我会返回来自更新(返回值)的项目列表。脚手架的Web API控制器是RESTful的,它不会从POST,PUT或DELETE中返回任何东西。
// DELETE api/<controller>/5
public **void** Delete(int id)
{
// delete...
}
在Angularjs我能想象一对夫妇的方法,以确保用户的列表始终是最新的。 (例如在$ scope中维护一个列表,并用POST/PUT/DELETE调用同时修改它,但看起来很麻烦)
Angularjs中使用REST风格确保最佳方法是什么?一个列表有准确的最新数据?如果没有一般的方法,在这个示例应用程序中处理它的最佳方式是什么。
由于Web API控制器是RESTful的,它不会从POST,PUT或DELETE_返回任何东西 - RESTful是没有理由不返回的ñ什么。 – zeroflagL 2014-09-28 19:05:28
感谢您的澄清,我想这只是一个Web API脚手架默认。 – lko 2014-09-28 19:13:39