简体   繁体   English

方括号前的符号

[英]At-sign before square brackets

I'm currently maintainging some DS/JS code in Demandware and I just found that : 我目前正在维护Demandware中的一些DS / JS代码,我发现:

var XmlReponse : XML = new XML(result.object.text);
status = XmlReponse.@["STATUS"];

What does this unusual "@[...]" syntax do ? 这种不寻常的“@ [...]”语法有什么作用?

It could have something to do with ECMA-357 specification (aka "E4X"), but I'm not sure : in the DW docs (needs credentials), it is said : 它可能与ECMA-357规范(又名“E4X”)有关,但我不确定:在DW文档 (需要凭证)中,它被说成:

"You can read values from an XML object the same way you would from standard ECMAScript objects" “您可以使用与标准ECMAScript对象相同的方式从XML对象读取值”

var quantity = order.item(0).@quantity;
var singleItem = order.item.(@quantity == 1);

That seems to explain the @ but let me skeptical about the following square brackets, maybe some kind of dynamic property ? 这似乎解释了@但让我对下面的方括号持怀疑态度,也许某种动态属性?

Thanks :) 谢谢 :)

From reading the manual it seems to read a property of an xml element. 从阅读 手册,它似乎读取了xml元素的属性。 I don't see that reading the indexer would be any different 我没有看到阅读索引器会有所不同

Your mentioned code would then read the attribute STATUS on the xmlresponse 然后,您提到的代码将读取xmlresponse上的属性STATUS

The code on the linked ex4 manual status: 链接ex4手册状态的代码:

E4X allows you to access the attributes of a particular element with the .@ operator. E4X允许您使用。@运算符访问特定元素的属性。 The most basic case would look something like. 最基本的情况看起来像。

var element = <foo bar="1"/>
element.@bar = 2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM