作为传递给$资源是什么@id? [英] What is @id as passed to $resource?
问题描述
$资源(/项/:ID,{ID:@id},{更新:{方法:PUT}})
什么是@id?
在$资源文档页面有人说这个下文,但我还是不明白。
如果该参数值是与@ pfixed则该值$ P $
参数从数据对象中提取(有用非GET
操作)。这里的数据对象是指POSTDATA
对象,如果
非GET阶级一词的动作,或者如果实例本身非GET
例如操作使用。
块引用>解决方案如果我理解正确这,我不得,参数
{ID:@Id}
是的另一种方法的说明图用一块数据的供给的url变量由于此方法:
VAR myResource = $资源(/职位/:theName
{theName:@petName},
{请输入:{
方法:POST,
IsArray的:假的
}
});如果我在我张贴的数据属性petName,该属性的值将被放置在
:在我的网址theName
变量。试想一下,POST数据是{petType:猫,petName:点}
,URL将读/职位/点
。在我的印象中,@
表示对象的属性来予以公布。拿走
@
从该值和url变量在资源参数将直接引用值:{theName:petName'} //没有@
// URL输出----> '/职位/ petName
下面是引用链:
// URL VAR - > // $资源参数{..} - >到发布//对象
:theName ---> {theName ----> @petName ---> {petName ---> 点只花了5个步骤来获得点到网址!
使用上述例子的资源实例的示例:
VAR POSTDATA =新myResource();
postData.petType =猫;
postData.petName =点;
POSTDATA。$输入({}功能(数据){
$ scope.data =数据;
})
// URL张贴到会'/职位/点,POSTDATA对象将是
// {petType:猫,petName:现货}在一个侧面说明,文档可以非常混乱。你曾经采取了艰难的历程和教授是一个杰出的人几乎没有谁讲你的语言?是啊。
$resource("/entries/:id", {id: "@id"}, {update: {method: "PUT"}})
What is @id?
On the $resource doc page someone says this below, but I still don't understand.
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
postData
object if non-GET "class" action is used, or the instance itself if non-GET instance action is used.
解决方案If I understand this correctly, and I may not, the parameter
{id: @id}
is an illustration of another way to supply your url variable with a piece of data.Given this method:
var myResource = $resource("/posts/:theName", {theName: '@petName'}, {enter : { method: "POST", isArray: false } });
If I have an attribute "petName" in the data that I'm posting, the value of that attribute will be placed in
:theName
variable in my url. Imagine the post data being{"petType": "cat", "petName": "Spot"}
, the url will read"/posts/Spot"
. In my mind, the@
means "attribute" of the object to be posted.Take away the
@
from that value, and the url variable will directly reference the value in that resource parameter:{theName: 'petName'} //no "@" // url output ----> '/posts/petName'
.
Here is the chain of references:
//url var--> //$resource param {..} --->//Object to be posted :theName---> {theName ----> @petName ---> {petName---> "Spot"
It only took 5 steps to get "Spot" into the url!
.
Example of a resource instance using the above example:
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"}
On a side note, the docs can be very confusing. Have you ever taken a difficult course and the professor was a brilliant man who barely spoke your language? Yup.
这篇关于作为传递给$资源是什么@id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!