Restangular - 指定自定义ID键

时间:2015-05-01 11:25:04

标签: javascript angularjs restangular angular-services

在Restangular中如果我声明一个服务,并执行PUT / PATCH / POST操作,它默认使用该项的id作为主键。但是,如果我们想使用自定义密钥呢?像slu or还是数字?

// GET to /users
Users.getList().then(function(users) {
  var user = users[0]; // user === {id: 1, number: 123456, name: "Tonto"}
  user.name = "Gonto";
  // PUT to /users/1 <-- Here the id is used. But I'd like to use number to post to PUT to /users/123456
  user.put();
})

0 个答案:

没有答案