gpt4 book ai didi

angularjs - 无需从服务器获取对象即可更新对象的 Retangular 选项

转载 作者:行者123 更新时间:2023-12-03 08:12:20 24 4
gpt4 key购买 nike

我已经开始使用 Restangular,它似乎是一个非常好的库。但是我有以下查询。为了更新一个对象,我使用下面的代码

Restangular.one("accounts", $scope.accountEdit.id).get().then(function(account) {
account = Restangular.copy($scope.accountEdit);
account.put();
});

在上面的代码中,我必须向服务器发出一个 get 请求,然后更新它。有没有更好的方法来避免服务器调用,因为我想将对象从我的范围更新到服务器。

最佳答案

您可以使用 customPUT像这样,

Restangular.one("accounts").customPUT($scope.accountEdit, $scope.accountEdit.id).then(function(account) {
TO-DO
});

customPUT([elem, path, params, headers]): Does a PUT to the specific path. Optionally you can set params and headers and elem. Elem is the element to post. If it's not set, it's assumed that it's the element itself from which you're calling this function.



除此之外,您还可以 使用 Restangular 扩展您的对象 这会给你与你的回调函数相同的结果......
angular.extend($scope.accountEdit, Restangular.one("accounts", $scope.accountEdit.id));
$scope.accountEdit.put();

关于angularjs - 无需从服务器获取对象即可更新对象的 Retangular 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22704733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com