Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

javascript - 什么是添加到我的JSON.stringify结果的$$ hashKey(What is the $$hashKey added to my JSON.stringify result)

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.

(我已经尝试查看他们的文档的Mozilla JSON stringify页面以及SO和Google,但没有找到任何解释。)

I have used JSOn stringify many time but never come across this result

(我已经多次使用JSOn stringify但从未遇到过这个结果)

I have an array of JSON objects

(我有一个JSON对象数组)

[
    {
        "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"
    }
]

attached to my $scope and in order to POST them as one paramater I used the JSON.stringify() method and I get the following:

(连接到我的$scope ,并以POST他们为我所用的JSON.stringify()方法,一个paramater,我得到以下几点:)

   [
        {
            "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 what exactly is the $$hashkey as I expected something more similar to the following from the stringify method:

(我只是很好奇究竟是什么是$$ hashkey,因为我期望与stringify方法中的以下内容更相似:)

[
    {
        "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 Angularjs 1.1.5, JQuery 1.8.2 and Spring 3.0.4 and Spring security 3.0.7 on the Server side

(我不确定它是否是一个因素,但我Angularjs 1.1.5, JQuery 1.8.2 and Spring 3.0.4 and Spring security 3.0.7 on the Server side使用Angularjs 1.1.5, JQuery 1.8.2 and Spring 3.0.4 and Spring security 3.0.7 on the Server side)

It is not causeing me any issues but I would like to know the cause and reason for the $$hashkey

(它不会引起任何问题,但我想知道$$hashkey的原因和原因)

  ask by jonnie translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Angular adds this to keep track of your changes, so it knows when it needs to update the DOM.

(Angular添加了这个以跟踪您的更改,因此它知道何时需要更新DOM。)

If you use angular.toJson(obj) instead of JSON.stringify(obj) then Angular will strip out these internal-use values for you.

(如果使用angular.toJson(obj)而不是JSON.stringify(obj)那么Angular将为您删除这些内部使用值。)

Also, if you change your repeat expression to use the track by {uniqueProperty} suffix, Angular won't have to add $$hashKey at all.

(此外,如果您track by {uniqueProperty}后缀更改重复表达式以使用track by {uniqueProperty} ,Angular将不必添加$$hashKey 。)

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.

(只需track by href肯定无法正常工作。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...