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'嗎?你是如何獲得資源的?什麼是「查詢」?我很困惑。這裏沒有任何背景。 –