【问题标题】:saving a restangular object under its "other" id在其“其他”ID下保存一个restangular对象
【发布时间】:2014-07-02 23:40:02
【问题描述】:

我有一个用于用户帐户的 REST 服务:

REST_URL/accounts/{:id}

当我登录后,我可以通过

获取我自己的帐户信息
REST_URL/accounts/me

这会返回一些类似的 json

{'id': 4, 'name': 'John'}

现在当我编辑名称并保存时,它会发布到

REST_URL/accounts/4

但我希望将其发布到

REST_URL/accounts/me

内容

{'id': 4, 'name': 'Johnny'}

这可能吗?我不想发送 {'id': 'me', 'name': 'Johnny'} 因为 'id' 在服务器上是数字。

这里是js代码:

Restangular.one('account', 'me').get().then(function(data) {
    $scope.account = data;
});

$scope.account.put();

【问题讨论】:

    标签: restangular


    【解决方案1】:

    不太好,但也许您可以使用 customPUT?

    Restangular.one('account', 'me')
    .customPUT({ 'id': 4, 'name': 'Jonny'  })
    .then(function(data) {
        // success
    });
    

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 2019-04-10
      • 2012-11-07
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多