AngularJS:是$$ hashkey可靠的关键 [英] AngularJS: is $$hashkey a reliable key

查看:309
本文介绍了AngularJS:是$$ hashkey可靠的关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

我感兴趣的 $$ hashkey 对角阵列/对象的属性。


  1. 将各自产生hashkey是相同每次重装时间
    页;快速测试告诉我,是的,但我有点假设它
    不会?

  2. 如果您更新/添加到现有阵列,将老hashkey的
    保持一致性?

  3. 如果上面是真实的,有没有办法使用从阵列获取
    该hashkey? - 事业我可以推出自己的,但我之前重新创建轮我认为我会问。

示例:

意见将包括:


  • 表格数据(例如有1表格)

  • 元素的数据(例如有2个元素)

  • 元素选项的数据(例如有每个单元的2个选项)

获取方式:

  angular.get($$ hashkey);

您会然后传递元件的hashkey,它将返回一个引用到完整阵列内部的阵列

最后的数据是:

  {
    form_id:1
    form_desc:'XXX',
    FORM_NAME:'名称1',
    内容:
        {
            element_id:1,
            ELEMENT_NAME:中element1',
            DEFAULT_VALUE:空,
            禁用:0
            ELEMENT_TYPE:形象,
            ElementOptions:
                {
                    显示:假的,
                    SORT_ORDER:0,
                    值:AR,
                },
                {
                    显示:真实,
                    SORT_ORDER:1,
                    值:RW
                }
            ]
        },
        {
            element_id:2,
            ELEMENT_NAME:在element2,
            DEFAULT_VALUE:空,
            禁用:0
            ELEMENT_TYPE:形象,
            ElementOptions:
                {
                    显示:假的,
                    SORT_ORDER:0,
                    值:AR,
                },
                {
                    显示:真实,
                    SORT_ORDER:1,
                    值:RW
                }
            ]
        }
    ]
}


解决方案

$$ HASHKEYS将只计算了函数和对象,所以如果你想跟踪任何不是这些类型之一,那么你有这个限制。

$$ HASHKEYS样子...
(函数||对象):N
...

其中N是刚刚被调整+ 1的增量值为每个$$ HashKey计算。
因此,在许多情况下,这可能是在整个页面加载相同的值。但是,这非同步加载数据,将在多个数据源被查询作为返回的页面初始化和秩序的一部分时不能保证产生分歧。在这样的情况下,你将不得不马歇尔所有的非同步数据,然后将数据分配到你的范围以特定的顺序,以确保一致$$ HASHKEYS。

在链接到我们的DOM(通过NG-重复)阵列中移动项目将不会改变该项目$$ hashkey。删除并重新添加它会的。

我不会,因为它旨在成为内部AngularJS使用$$ Hashkey为我自己的看家。

Question

I'm interested in the properties of $$hashkey on angular arrays/objects.

  1. Would each generated hashkey be the same each time you reload a page; a quick test tells me yes but I somewhat assumed it wouldn't?
  2. If you updated/added to the existing array, would the old hashkey's stay consistent?
  3. If the above is true, is there a way to fetch from an array using the hashkey? - of cause I could roll my own but before I recreate the wheel I thought I'd ask.

Example:

Views would include:

  • form data (example has 1 form)
  • element data (example has 2 elements)
  • element options data (example has 2 options per element)

Fetch method:

angular.get($$hashkey);

You would then pass the hashkey of the element and it would return a reference to that array inside the full array.

Lastly the data would be:

{
    form_id: 1
    form_desc: 'xxx',
    form_name: 'name 1',
    Elements: [
        {
            element_id: 1,
            element_name: 'element1',
            default_value: null,
            disabled: "0",
            element_type: "image",
            ElementOptions: [
                {
                    show: false,
                    sort_order: 0,
                    value: "ar",
                },
                {
                    show: true,
                    sort_order: 1,
                    value: "rw",
                }
            ],
        },
        {
            element_id: 2,
            element_name: 'element2',
            default_value: null,
            disabled: "0",
            element_type: "image",
            ElementOptions: [
                {
                    show: false,
                    sort_order: 0,
                    value: "ar",
                },
                {
                    show: true,
                    sort_order: 1,
                    value: "rw",
                }
            ],
        }
    ]
}

解决方案

$$hashkeys will only be computed for functions and objects so if you wish to track anything that isn't one of those types then you have that limitation.

$$Hashkeys look like ... (function||object): N ...

Where N is just an incremental value being adjusted + 1 for each $$HashKey computed. So, in many cases this could be the same value across page loads. But loading data that is asynch, will cause differences when multiple data sources are being queried as part of page initialization and order of return cannot be guranteed. In cases like that you would have to marshall all your asynch data and then assign that data to your scope in a specific order to ensure consistent $$hashkeys.

Moving items around in an array that is linked to our DOM (via ng-repeat) will not change that items $$hashkey. Deleting it and re-adding it will.

I would not use $$Hashkey for my own housekeeping as it is intended to be internal to AngularJS.

这篇关于AngularJS:是$$ hashkey可靠的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆