[英]eBay JavaScript API - @ symbol in object member name
I am using the eBay JavaScript Finding API. 我正在使用eBay JavaScript Finding API。 The currency id member of the
findItemsAdvancedResponse
object is defined as @currencyId
. findItemsAdvancedResponse
对象的currency id成员定义为@currencyId
。 So I am retrieving this value as: 所以我检索这个值为:
function _cb_findItemsAdvanced(root) {
var items = root.findItemsAdvancedResponse[0].searchResult[0].item || [];
var html = [];
if (items.length == 0) {
html.push('No Results');
}
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
var price = Number(item.sellingStatus[0].currentPrice[0].`__value__`).toFixed(2);
var currency = ""
var currency = item.sellingStatus[0].currentPrice[0].@currencyId;
if (null != title && null != viewitem) {
html.push('<div class="item-layout5"><table><tr><td><div style="width:102px;overflow:hidden;">');
html.push('<a href="' + viewitem + '" target="_blank" rel="nofollow"><img src="' + pic + '" border= "" alt="' + title + '" /></a></div></td>');
html.push('<td><span class="itemname"><a href="' + viewitem + '">' + title + '</a></span></td></tr>');
html.push('<tr><td><img src="PTMFOG0000000064.gif" alt="" /></td><td><span class="buyprice">' + currency + ' $' + price + '</span></td></tr></table></div>');
}
}
document.getElementById("results").innerHTML = html.join("");
} // End _cb_findItemsByKeywords() function
This works fine for Firefox browsers, but not for Google Chrome or IE (I get a compilation error). 这适用于Firefox浏览器,但不适用于谷歌浏览器或IE浏览器(我收到编译错误)。
Is using the @ symbol in a member name acceptable in JavaScript? 在JavaScript中可接受的成员名称中使用@符号? And what workaround can I use so that the above code will work in all browsers?
我可以使用哪种解决方法,以便上述代码适用于所有浏览器?
Thanks 谢谢
In javascript, the syntax 在javascript中,语法
foo.bar
is equivalent to 相当于
foo['bar']
and the latter works even when 'bar' is not a valid identifier name, as in this case. 即使'bar'不是有效的标识符名称,后者也可以工作,就像在这种情况下一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.