加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Restangular函数中的’Route’有什么用途oneUrl()

发布时间:2020-12-17 07:24:07 所属栏目:安全 来源:网络整理
导读:这是oneUrl函数的签名:oneUrl(route,url) 并从文档: oneUrl(route,url) : This will create a new Restangular object that is just a pointer to one element with the specified URL. 对我来说,在为资源提??供URL时设置Route似乎没用.为什么它存在于参数
这是oneUrl函数的签名:oneUrl(route,url)
并从文档:

oneUrl(route,url): This will create a new Restangular object that is
just a pointer to one element with the specified URL.

对我来说,在为资源提??供URL时设置Route似乎没用.为什么它存在于参数列表中?为什么强制要求?它怎么用?

在我使用oneUrl时,我发现路由名称用于构建后续PUT和DELETE操作的URL.例如(伪代码):
// "GET /api/v2/users/3/ HTTP/1.1" 200 184
var user = Restangular.oneUrl('myuser','http://localhost:8000/api/v2/users/3').get();
user.name = 'Fred';
// the following uses the route name and not the URL:
// "PUT /api/v2/myuser HTTP/1.1 404 100
user.put();

我对这种行为感到惊讶.我希望put()使用与get()相同的URL;这在我的情况下会有所帮助.

我的API使用JSON有效内容中的绝对URL导航到所有相关资源,我想使用oneUrl()到GET / PUT实例,而无需重新创建JS代码中的路由.但我对Restangular很新,所以我可能没有正确的心理模型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读