What is the $$hashKey added to my JSON.stringify result(什么是 $$hashKey 添加到我的 JSON.stringify 结果)
问题描述
I have tried looking on the Mozilla JSON stringify page of their docs as well as here on SO and Google but found no explanation. I have used JSON.stringify
many time but never come across this result.
I have an array of JSON objects:
[
{
"param_2": "Description 1",
"param_0": "Name 1",
"param_1": "VERSION 1"
},
{
"param_2": "Description 2",
"param_0": "Name 2",
"param_1": "VERSION 2"
},
{
"param_2": "Description 3",
"param_0": "Name 3",
"param_1": "VERSION 3"
}
]
It is attached to my $scope
. In order to POST
them as one parameter, I used the JSON.stringify()
method and receive the following:
[
{
"param_2": "Description 1",
"param_0": "Name 1",
"param_1": "VERSION 1",
"$$hashKey": "005"
},
{
"param_2": "Description 2",
"param_0": "Name 2",
"param_1": "VERSION 2",
"$$hashKey": "006"
},
{
"param_2": "Description 3",
"param_0": "Name 3",
"param_1": "VERSION 3",
"$$hashKey": "007"
}
]
I am just curious about what the $$hashkey
property is exactly, as I expected something more similar to the following from the stringify
method (that is, without the $$hashkey
):
[
{
"1":{
"param_2": "Description 1",
"param_0": "Name 1",
"param_1": "VERSION 1"
},
"2":{
"param_2": "Description 2",
"param_0": "Name 2",
"param_1": "VERSION 2"
},
"3":{
"param_2": "Description 3",
"param_0": "Name 3",
"param_1": "VERSION 3"
}
}
]
I am not sure if it is a factor, but I am using the following:
- Angularjs 1.1.5,
- JQuery 1.8.2
- Spring 3.0.4
I'm also using Spring security 3.0.7 on the Server side.
It is not causing me any issues, but I would like to know the cause and reason for the $$hashkey
Angular adds this to keep track of your changes, so it knows when it needs to update the DOM.
If you use angular.toJson(obj)
instead of JSON.stringify(obj)
then Angular will strip out these internal-use values for you.
Also, if you change your repeat expression to use the track by {uniqueProperty}
suffix, Angular won't have to add $$hashKey
at all. For example
<ul>
<li ng-repeat="link in navLinks track by link.href">
<a ng-href="link.href">{{link.title}}</a>
</li>
</ul>
Just always remember you need the "link." part of the expression - I always tend to forget that. Just track by href
will surely not work.
这篇关于什么是 $$hashKey 添加到我的 JSON.stringify 结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是 $$hashKey 添加到我的 JSON.stringify 结果


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01