【问题标题】:Put Object in Restangular将对象放入 Restangular
【发布时间】:2015-08-30 17:26:44
【问题描述】:

您会在下面看到我的代码,以使用 restangular 从我的数据库中更改记录。

Restangular.one("/mywebsite/bin/server.fcgi/REST/players", "70").get().then(function(c){
          $scope.content = c;
        })

        $scope.content.Name= "Asqan";

        $scope.content.put();

当我尝试将代码作为最后一行时,它给出了错误:

PUT http://localhost/mywebsite/bin/server.fcgi/REST/players 404 (Object not found)

ps:添加或获取没有其他问题。

【问题讨论】:

  • 您的.get 函数是异步的,所以当它到达$scope.content 时,它可能为空/未定义
  • 是的。这次错误:“未知属性:id”。这是因为该属性在我的数据库中定义为“ID”吗?如果是这样,我应该如何改变这个?
  • 是的,参数offcourse应该匹配,否则属性将不存在
  • 那么,具体应该怎么做呢?
  • 使用你拥有的属性,所以如果是ID,那么使用ID

标签: angularjs rest angularjs-scope restangular


【解决方案1】:

你应该在 then 函数中这样做,

Restangular.one("/mywebsite/bin/server.fcgi/REST/players", "70").get().then(function(c){

      $scope.content = c;
      $scope.content.Name= "Asqan";
      $scope.content.put();
})

【讨论】:

  • 结果是一样的。这是我的第一次实施。我后来以这种方式尝试过,因为我已经看到在类似的问题中作为解决方案提供了这种方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-22
  • 1970-01-01
相关资源
最近更新 更多