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

angularjs – 传递给$resource的@id是什么?

发布时间:2020-12-17 09:01:50 所属栏目:安全 来源:网络整理
导读:$resource("/entries/:id",{id: "@id"},{update: {method: "PUT"}}) 什么是@id? 在$ resource doc page有人这样说下,但我还是不明白。 If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object (u
$resource("/entries/:id",{id: "@id"},{update: {method: "PUT"}})

什么是@id?

在$ resource doc page有人这样说下,但我还是不明白。

If the parameter value is prefixed with @ then the value of that
parameter is extracted from the data object (useful for non-GET
operations).” The data object here refers to the postDataobject if
non-GET “class” action is used,or the instance itself if non-GET
instance action is used.

如果我正确理解这一点,而我可能不会,参数{id:@id}是另一种方式为您的url变量提供一段数据的例证。

给定这个方法:

var myResource = $resource("/posts/:theName",{theName: '@petName'},{enter : {
                                      method: "POST",isArray: false
                                     }
                            });

如果我在我发布的数据中有属性“petName”,该属性的值将放置在:url中的theName变量。假设发布数据为{“petType”:“cat”,“petName”:“Spot”},网址将显示为“/ posts / Spot”。在我看来,@表示要发布的对象的“属性”。

从该值中取出@,url变量将直接引用该资源参数中的值:

{theName: 'petName'} //no "@"
// url output ---->   '/posts/petName'

这里是参考链:

//url var--> //$resource param {..}  --->//Object to be posted
:theName---> {theName ----> @petName ---> {petName---> "Spot"

它只需要5个步骤,以获得“Spot”进入网址!

使用上面示例的资源实例示例:

var postData = new myResource();
    postData.petType = "cat";
    postData.petName = "Spot";
    postData.$enter({},function(data){
        $scope.data = data;
    })
    // url to post to will be '/posts/Spot',postData object will be 
    //  {"petType":"cat","petName:"Spot"}

从旁边来看,文档可能很混乱。你有没有走过一个困难的课程,教授是一个辉煌的人,几乎不说你的语言?对。

(编辑:李大同)

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

    推荐文章
      热点阅读