gpt4 book ai didi

javascript - jQuery Datalink - 数据链接

转载 作者:行者123 更新时间:2023-11-29 17:32:08 26 4
gpt4 key购买 nike

我正在试用 jQuery Data linking proposal from Microsoft 并注意到一些奇怪的事情。

我的对象获得了这个额外的属性,我想知道这是什么原因。我起初以为这是我犯的一个错误,但我注意到他们的演示页面做同样的事情

这是我的对象的 json 结果:

[{
"propertyName":"ProductNamese",
"controlType":"Text",
"jQuery1274021322131":6
},
{
"propertyName":"Price",
"controlType":"Number",
"jQuery1274021322131":9
},
{
"propertyName":"Description",
"controlType":"TextArea",
"jQuery1274021322131":12
}
]

我说的属性是“jQuery1274021322131”。

最佳答案

当您将 DOM 对象转换为 jQuery 对象时(即 $("#SomeElementID")),jQuery 会向该对象附加一个特殊的“expando”属性。我相信此属性由库在内部使用,以帮助将元素缓存在其内部数组中以便更快地访问。

通过库挖掘,这是创建该值的代码及其在内部的使用方式:

    var expando = "jQuery" + now(), uuid = 0, windowData = {};

jQuery.extend({
cache: {},

data: function( elem, name, data ) {
elem = elem == window ?
windowData :
elem;

var id = elem[ expando ];

// Compute a unique ID for the element
if ( !id )
id = elem[ expando ] = ++uuid;

// Only generate the data cache if we're
// trying to access or manipulate it
if ( name && !jQuery.cache[ id ] )
jQuery.cache[ id ] = {};

// Prevent overriding the named cache with undefined values
if ( data !== undefined )
jQuery.cache[ id ][ name ] = data;

// Return the named cache data, or the ID for the element
return name ?
jQuery.cache[ id ][ name ] :
id;
},
// snipped

关于javascript - jQuery Datalink - 数据链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2844202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com