1
在AngularJS documentation中,似乎只能保存现有的对象,而不是新的对象。也就是说,在$resource
上有一个采用零参数的$save
方法。
如何对我POST
a 新对象使用$resource
对服务器?
该文件严重缺乏。
在AngularJS documentation中,似乎只能保存现有的对象,而不是新的对象。也就是说,在$resource
上有一个采用零参数的$save
方法。
如何对我POST
a 新对象使用$resource
对服务器?
该文件严重缺乏。
Resource.save
将该对象作为参数。
http://docs.angularjs.org/api/ngResource.$resource
var Item = $resource("/api/items/:id", {id: "@id"});
//Item is the "model", you have the method unprefixed
$scope.items = [];
$scope.addItem = function() {
var item = Item.save({name: $scope.newItemName}); //unprefix call
$scope.items.push(item);
$scope.newItemName = '';
};
$scope.saveItem = function (item) {
// item is, this time, a "Item instance" (returned by Item.save)
// and has the functions prefixed
item.$save();
}
从我们的聊天,似乎这已经足够了(最低限度)以POST
对象:
$resource('/some/path').save({name: 'Fred'});
什么是'Item'? –
这是资源 – Ven
这是一个'$资源'?你的意思是'$ save'而不是'save'吗?你是如何获得资源的?什么是“查询”?我很困惑。这里没有任何背景。 –